customizing xmetal page preview

21
© 2011 JustSystems Inc. © 2011 JustSystems Inc. in 37 minutes Episode 18 What WILL my output look like? Customizing XMetaL’s Page Preview Brought to you by XMetaL Technical Services Tom Magliery, XML Technology Specialist

Upload: xmetal

Post on 22-Apr-2015

1.974 views

Category:

Technology


0 download

DESCRIPTION

XMetaL Author's "Page Preview" is intended to show a preview of how your document will look when it is published. Without any customization, this is simply an HTML view that approximates the appearance of the document in Normal View in the editor. In this webinar we'll show you how to customize the Page Preview to match your real published output, including using your own style sheets, and providing either HTML or PDF previews. Please note: This webinar is intended for customizers and users of non-DITA document types. For DITA users, XMetaL already provides page previews using the DITA Open Toolkit. Also note that we'll be diving into some script code, so it will be lightly technical.

TRANSCRIPT

Page 1: Customizing XMetaL Page Preview

© 2011 JustSystems Inc.© 2011 JustSystems Inc.

in 37 minutes

Episode 18

What WILL my output look like?

Customizing XMetaL’s Page Preview

Brought to you by XMetaL Technical Services

Tom Magliery, XML Technology Specialist

Page 2: Customizing XMetaL Page Preview

© 2011 JustSystems Inc.

Announcements

• XMetaL Author 6.0 SP1• TopLeaf plug-in

Page 3: Customizing XMetaL Page Preview

© 2011 JustSystems Inc.

• Demo 0: baseline– Look at the default HTML preview

• Demo 1: low-hanging fruit– Replacing the default HTML transformation

• Demo 2: user control– Making a user macro to generate the preview

• Demo 3: PDF, too– Doing the above stuff with PDF

• Demo 4: HTML PDF– Changing the “default” mode for page preview

• Demo 5: non-XSLT– Using script instead of XSLT for the transformation

Agenda

Page 4: Customizing XMetaL Page Preview

© 2011 JustSystems Inc.

• XMetaL automatically generates a preview

• It approximates thein-editor CSS styles

• The code for this is in $XMDIR\Author\Startup\multipleOutput.mcr

Demo 0: baseline

Page 5: Customizing XMetaL Page Preview

© 2011 JustSystems Inc.

• On_Before_Document_Preview macro– Verifies and/or regenerates XSLT– Transform uses three XSLT files:

1. Auto-generated XSLT (based on CSS styles)

2. Your custom XSLT (if it exists)

3. A “master” file that imports these other two

– Runs XSLT and saves output to temp file– Sets ActiveDocument.BrowserURL property

• This tells XMetaL what page to send to the browser upon entering Page Preview

• The good news: the process for much of the above is encapsulated and accessible

How it works

Page 6: Customizing XMetaL Page Preview

© 2011 JustSystems Inc.

• Add a custom style sheet• It’s as easy as 0-1-2:

0. Create an XSLT style sheet

1. Give it the correct filename

2. Put it in the correct place

• Note: Step 0 is outside the scope of this webinar!*

Demo 1: low-hanging fruitReplacing the default HTML transformation

* Many folks would also say Step 0 is not easy

Page 7: Customizing XMetaL Page Preview

© 2011 JustSystems Inc.

• If your DTD or schema name is “foo” ...• ... then your style sheet must have this name:

foo_HTML_Custom.xsl

• Our sample DTD is called “simplepaper”, hence:

simplepaper_HTML_Custom.xsl

Step 1: What to name it

Page 8: Customizing XMetaL Page Preview

© 2011 JustSystems Inc.

• If limited-user restrictions are enabled (as they are by default):

%APPDATA%\SoftQuad\XMetaL\6.0\Display\

• For example, right now mine is here:C:\Documents and Settings\tmagliery\Application Data\SoftQuad\XMetaL\6.0\Display\

• If limited-user restrictions are disabled:C:\Program Files\XMetaL 6.0\Author\Display\

• If you see these other two files here, remove them now (they will need to be re-auto-generated):

foo_HTML.xslfoo_HTML_Style.xsl

Step 2: Where to put it*

* In the folder where XMetaL is going to look for it, of course

Page 9: Customizing XMetaL Page Preview

© 2011 JustSystems Inc.

• “Helper” scriptfunctions defined in multipleOutput.mcr

• Call the helper functions in user macros

• Add this macro to your document MCR file

Demo 2: user control Making a user macro to generate the preview

<MACRO name="Do my HTML preview" lang="JScript" hide="false"><![CDATA[ previewHTML();]]></MACRO>

Page 10: Customizing XMetaL Page Preview

© 2011 JustSystems Inc.

• previewHTML()• previewPDF()• saveAsHTML()• saveAsPDF()• XMLtoHTMLSetup()• XMLtoPDFSetup()

Helper functions available

Page 11: Customizing XMetaL Page Preview

© 2011 JustSystems Inc.

• Architecture is similar to HTML– On_Before_Document_Preview macro– Verify and regenerate XSLT– Run XSLT transform saving output to temp file– Set the Application.BrowserURL property

• Add another macro for previewing PDF

Demo 3: PDF, too Doing the above stuff with PDF

<MACRO name="Do my PDF preview" lang="JScript" hide="false"><![CDATA[ previewPDF();]]></MACRO>

Page 12: Customizing XMetaL Page Preview

© 2011 JustSystems Inc.

• Custom style sheet file is:

simplepaper_Custom.xsl

• Same directory as the HTML style sheetsC:\Documents and Settings\tmagliery\

Application Data\SoftQuad\XMetaL\6.0\Display\

Custom XSLT for PDF

Page 13: Customizing XMetaL Page Preview

© 2011 JustSystems Inc.

• XMetaL remembers a “preview mode” setting for each open document

• Global array (hash) aMOFormat defined in multipleOutput.mcr

• Make user macros that set array entry to “HTML” or “PDF” for current document

• Subsequently Page Preview will use that format

Demo 4: HTML PDFChanging the “default” mode for page preview

<MACRO name="_Set Preview Mode to PDF" lang="JScript" hide="false"><![CDATA[ aMOFormat[ActiveDocument.FullName + "|" + ActiveDocument.Title] = "PDF";]]></MACRO>

Page 14: Customizing XMetaL Page Preview

© 2011 JustSystems Inc.

• The code samples in this webinar have been tested with XMetaL Author 6.0.1.030.

• Unfortunately, I know there were some changes to multipleOutput.mcr in this version of XMetaL, which means some of my sample code may not work with other versions.

• This concludes the “working with XSLT” portion of the webinar.

Special note

Page 15: Customizing XMetaL Page Preview

© 2011 JustSystems Inc.

But I don’t wanna use XSLT!!

Page 16: Customizing XMetaL Page Preview

© 2011 JustSystems Inc.

Demo 5: non-XSLTUsing script instead of XSLT for the transformation

• XSLT is not the only way to generate output from XML

• Make your own On_Before_Document_Preview in document-level MCR file– This macro will “win” over the one in multipleOutput.mcr

– Do whatever scripting you want to perform the transformation

• One possibility: – Invent a new “preview mode” such as “MyHTML”– Follow the general pattern used by the OBDP in multipleOutput.mcr

Page 17: Customizing XMetaL Page Preview

© 2011 JustSystems Inc.

Adding a new “preview mode” to OBDP

//Pseudocode/algorithm from existing OBDP:If MOFormat is "HTML"

XSLT transform with HTML output Set the "BrowserURL" property

Else if MOFormat is "PDF"XSLT transform with PDF output Set the "BrowserURL" property

//new for this example:Else if MOFormat is "MyHTML"

Custom script to make HTML output Set the "BrowserURL" property

Page 18: Customizing XMetaL Page Preview

© 2011 JustSystems Inc.

• Pick out some bits and pieces:

Logic for demo HTML output

var htmlStr = "<html><body>";// pick out and use the main title of the papervar ndlist = ActiveDocument.getNodesByXPath("Paper/Title");htmlStr += "<h1>" + ndlist.item(0).firstChild.nodeValue + "</h1>\n";// do some processing for each one of the sectionsvar sections = ActiveDocument.getNodesByXPath("Paper/Section");for (var i=0; i<sections.length; i++){

var sect = sections.item(i);// pick out and use the section titlevar secttitle = sect.getNodesByXPath("Title");htmlStr += "<h2>" + secttitle.item(0).firstChild.nodeValue + "</h2>\n";// do some processing for each of the paragraphs in this sectionvar paragraphs = sect.getNodesByXPath("Para");for (var j=0; j<paragraphs.length; j++){

var para_node = paragraphs.item(i);htmlStr += "<p>" + para_node.firstChild.nodeValue + "</p>\n";

}}htmlStr += "</body></html>";

Page 19: Customizing XMetaL Page Preview

© 2011 JustSystems Inc.

• We have seen how to:– Customize the default page-preview XSLT– Make user macros to generate HTML and PDF

previews– Change and manage the page-preview output type– Use custom script instead of XSLT for the preview

transformation

• Whew!

Summary

Page 20: Customizing XMetaL Page Preview

© 2011 JustSystems Inc.

• XMetaL Community Forums– http://forums.xmetal.com/

• JustSystems Partner Center– http://justpartnercenter.com/

• Ask us for help (partner tech support)– [email protected]

Resources

Page 21: Customizing XMetaL Page Preview

© 2011 JustSystems Inc.

• Thank you for attending!

Q&A