"Pushing" Content from an XML File
In the "push" approach, the structure and order of elements in the transformed results are usually defined by the source XML file. In the case of OXML, the structure of the XML mimics the nested tree structure of the Viewer outline, and we can construct a very simple XSLT transformation to reproduce the outline structure.
This example generates the contents of the outline pane in HTML, but it could just as easily generate a simple text file. The XSLT stylesheet is oms_simple_outline_example.xsl.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
xmlns:oms="http://xml.spss.com/spss/oms">
<xsl:template match="/">
<HTML>
<HEAD>
<TITLE>Outline Pane</TITLE>
</HEAD>
<BODY>
<br/>Output
<xsl:apply-templates/>
</BODY>
</HTML>
</xsl:template>
<xsl:template match="oms:command|oms:heading">
<xsl:call-template name="displayoutline"/>
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="oms:textBlock|oms:pageTitle|oms:pivotTable|oms:chartTitle">
<xsl:call-template name="displayoutline"/>
</xsl:template>
<!--indent based on number of ancestors:
two spaces for each ancestor-->
<xsl:template name="displayoutline">
<br/>
<xsl:for-each select="ancestor::*">
<xsl:text>  </xsl:text>
</xsl:for-each>
<xsl:value-of select="@text"/>
<xsl:if test="not(@text)">
<!--no text attribute, must be page title-->
<xsl:text>Page Title</xsl:text>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
-
xmlns:oms="http://xml.spss.com/spss/oms"
defines "oms" as the prefix that identifies the namespace, so all element names in XPath expressions need to include the prefix "oms:". - The stylesheet consists mostly of two template elements
that cover each type of element that can appear in the outline—
command
,heading
,textBlock
,pageTitle
,pivotTable
, andchartTitle
. - Both of those templates call another template that
determines how far to indent the
text
attribute value for the element. - The
command
andheading
elements can have other outline items nested under them, so the template for those two elements also includes<xsl:apply-templates/>
to apply the template for the other outline items. - The template that determines the outline indentation
simply counts the number of "ancestors" the element has, which indicates
its nesting level, and then inserts two spaces (  is a "nonbreaking"
space in HTML) before the value of the
text
attribute value. -
<xsl:if test="not(@text)">
selects<pageTitle>
elements because this is the only specified element that doesn't have atext
attribute. This occurs wherever there is aTITLE
command in the command file. In the Viewer, it inserts a page break for printed output and then inserts the specified page title on each subsequent printed page. In OXML, the<pageTitle>
element has no attributes, so we use<xsl:text>
to insert the text "Page Title" as it appears in the Viewer outline.
Viewer Outline "Titles"
You may notice that there are a number of "Title" entries in the
Viewer outline that don't appear in the generated HTML. These should
not be confused with page titles. There is no corresponding element
in OXML because the actual "title" of each output block (the text
object selected in the Viewer if you click the "Title" entry in the
Viewer outline) is exactly the same as the text of the entry directly
above the "Title" in the outline, which is contained in the text
attribute of the corresponding command
or heading
element in OXML.