Customizing XMetaL Page Preview

2,000 views
1,844 views

Published on

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.

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
2,000
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
23
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Customizing XMetaL Page Preview

  1. 1. in 37 minutes<br />Episode 18<br />What WILL my output look like?<br />Customizing XMetaL’s Page Preview<br />Tom Magliery, XML Technology Specialist<br />Brought to you by XMetaL Technical Services<br />
  2. 2. Announcements<br />XMetaL Author 6.0 SP1<br />TopLeaf plug-in<br />
  3. 3. Demo 0: baseline<br />Look at the default HTML preview<br />Demo 1: low-hanging fruit<br />Replacing the default HTML transformation<br />Demo 2: user control<br />Making a user macro to generate the preview<br />Demo 3: PDF, too<br />Doing the above stuff with PDF<br />Demo 4: HTML  PDF<br />Changing the “default” mode for page preview<br />Demo 5: non-XSLT<br />Using script instead of XSLT for the transformation <br />Agenda<br />
  4. 4. XMetaL automatically generates a preview<br />It approximates thein-editor CSS styles<br />The code for this is in $XMDIRAuthorStartupmultipleOutput.mcr<br />Demo 0: baseline<br />
  5. 5. On_Before_Document_Preview macro<br />Verifies and/or regenerates XSLT<br />Transform uses three XSLT files:<br />Auto-generated XSLT (based on CSS styles)<br />Your custom XSLT (if it exists)<br />A “master” file that imports these other two<br />Runs XSLT and saves output to temp file<br />Sets ActiveDocument.BrowserURL property<br />This tells XMetaL what page to send to the browser upon entering Page Preview<br />The good news: the process for much of the above is encapsulated and accessible<br />How it works<br />
  6. 6. Add a custom style sheet<br />It’s as easy as 0-1-2:<br />0. Create an XSLT style sheet<br />Give it the correct filename<br />Put it in the correct place<br />Note: Step 0 is outside the scope of this webinar!*<br />Demo 1: low-hanging fruitReplacing the default HTML transformation<br />* Many folks would also say Step 0 is not easy<br />
  7. 7. If your DTD or schema name is “foo” ...<br />... then your style sheet must have this name:<br />foo_HTML_Custom.xsl<br />Our sample DTD is called “simplepaper”, hence:<br />simplepaper_HTML_Custom.xsl<br />Step 1: What to name it<br />
  8. 8. If limited-user restrictions are enabled (as they are by default):<br /> %APPDATA%SoftQuadXMetaL6.0Display<br />For example, right now mine is here:<br /> C:Documents and SettingstmaglieryApplication DataSoftQuadXMetaL6.0Display<br />If limited-user restrictions are disabled:<br /> C:Program FilesXMetaL 6.0AuthorDisplay<br />If you see these other two files here, remove them now (they will need to be re-auto-generated):<br /> foo_HTML.xsl<br /> foo_HTML_Style.xsl<br />Step 2: Where to put it*<br />* In the folder where XMetaL is going to look for it, of course<br />
  9. 9. “Helper” scriptfunctions defined in multipleOutput.mcr<br />Call the helper functions in user macros<br />Add this macro to your document MCR file<br />Demo 2: user control Making a user macro to generate the preview<br /><MACRO name="Do my HTML preview" lang="JScript" hide="false"><![CDATA[<br />previewHTML();<br />]]></MACRO><br />
  10. 10. previewHTML()<br />previewPDF()<br />saveAsHTML()<br />saveAsPDF()<br />XMLtoHTMLSetup()<br />XMLtoPDFSetup()<br />Helper functions available<br />
  11. 11. Architecture is similar to HTML<br />On_Before_Document_Preview macro<br />Verify and regenerate XSLT<br />Run XSLT transform saving output to temp file<br />Set the Application.BrowserURL property<br />Add another macro for previewing PDF<br />Demo 3: PDF, too Doing the above stuff with PDF<br /><MACRO name="Do my PDF preview" lang="JScript" hide="false"><![CDATA[<br />previewPDF();<br />]]></MACRO><br />
  12. 12. Custom style sheet file is:<br />simplepaper_Custom.xsl<br />Same directory as the HTML style sheets<br />C:Documents and SettingstmaglieryApplication DataSoftQuadXMetaL6.0Display<br />Custom XSLT for PDF<br />
  13. 13. XMetaL remembers a “preview mode” setting for each open document<br />Global array (hash) aMOFormat defined in multipleOutput.mcr<br />Make user macros that set array entry to “HTML” or “PDF” for current document<br />Subsequently Page Preview will use that format<br />Demo 4: HTML  PDFChanging the “default” mode for page preview<br /><MACRO name="_Set Preview Mode to PDF" lang="JScript" hide="false"><![CDATA[<br />aMOFormat[ActiveDocument.FullName + "|" + ActiveDocument.Title] = "PDF";<br />]]></MACRO><br />
  14. 14. The code samples in this webinar have been tested with XMetaL Author 6.0.1.030.<br />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.<br />This concludes the “working with XSLT” portion of the webinar.<br />Special note<br />
  15. 15. But I don’t wanna use XSLT!!<br />
  16. 16. Demo 5: non-XSLTUsing script instead of XSLT for the transformation <br />XSLT is not the only way to generate output from XML<br />Make your own On_Before_Document_Preview in document-level MCR file<br />This macro will “win” over the one in multipleOutput.mcr<br />Do whatever scripting you want to perform the transformation<br />One possibility: <br />Invent a new “preview mode” such as “MyHTML”<br />Follow the general pattern used by the OBDP in multipleOutput.mcr<br />
  17. 17. Adding a new “preview mode” to OBDP<br />//Pseudocode/algorithm from existing OBDP:<br />If MOFormat is "HTML"<br /> XSLT transform with HTML output Set the "BrowserURL" property<br />Else if MOFormat is "PDF"<br /> XSLT transform with PDF output Set the "BrowserURL" property<br />//new for this example:<br />Else if MOFormat is "MyHTML"<br /> Custom script to make HTML output Set the "BrowserURL" property<br />
  18. 18. Pick out some bits and pieces:<br />Logic for demo HTML output<br />varhtmlStr = "<html><body>";<br /> // pick out and use the main title of the paper<br />varndlist = ActiveDocument.getNodesByXPath("Paper/Title");<br />htmlStr += "<h1>" + ndlist.item(0).firstChild.nodeValue + "</h1>n";<br /> // do some processing for each one of the sections<br />var sections = ActiveDocument.getNodesByXPath("Paper/Section");<br /> for (vari=0; i<sections.length; i++)<br /> {<br />var sect = sections.item(i);<br /> // pick out and use the section title<br />varsecttitle = sect.getNodesByXPath("Title");<br />htmlStr += "<h2>" + secttitle.item(0).firstChild.nodeValue + "</h2>n";<br /> // do some processing for each of the paragraphs in this section<br />var paragraphs = sect.getNodesByXPath("Para");<br /> for (var j=0; j<paragraphs.length; j++)<br /> {<br />varpara_node = paragraphs.item(i);<br />htmlStr += "<p>" + para_node.firstChild.nodeValue + "</p>n";<br /> }<br /> }<br />htmlStr += "</body></html>";<br />
  19. 19. We have seen how to:<br />Customize the default page-preview XSLT<br />Make user macros to generate HTML and PDF previews<br />Change and manage the page-preview output type<br />Use custom script instead of XSLT for the preview transformation <br />Whew!<br />Summary<br />
  20. 20. XMetaL Community Forums<br />http://forums.xmetal.com/<br />JustSystems Partner Center<br />http://justpartnercenter.com/<br />Ask us for help (partner tech support)<br />partnersupport-na@justsystems.com<br />Resources<br />
  21. 21. Thank you for attending!<br />Q&A<br />

×