[xsl] Temporary Trees and Parser Upgrades

Subject: [xsl] Temporary Trees and Parser Upgrades
From: "Mark Shellenberger" <mshellenberger@xxxxxxxxx>
Date: Tue, 10 Apr 2007 18:09:58 -0400
XSLT Gurus,

I have the following stylesheet that  worked when parsing with Saxon
8.8.04 but no longer works with Saxon 8.9.  I  assume this is because
some aspect of either xsl:variable or document() was  tightened up to
the standard and my implementation was sub-standard. The final  goal
of this stylesheet is to take in a single lookup table containing file
pairs, combine the category element values of the category file with
the entire  content of the article in the pair.  The output would have
the category elements  as children of the categories element.  The
combined structure would be output  with the doi as the filename.
There will be one output file for each pair of  input documents
identified in the lookup table.

I imagine that this stylesheet is a  wonder of missed opportunities
and strangely used structures.  I'd appreciate  any constructive
comments you have on it.  But, since it worked in Saxon 8.8 and  I now
need to use Saxon 8.9, my major concern is figuring out why it no
longer  works.

I leave myself to your tender mercies.

--Mark

xslt 2.0 file

<?xml version="1.0"  encoding="UTF-8"?>
<xsl:stylesheet  xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
version="2.0">
   <xsl:output method="xml"  indent="yes"/>
   <xsl:template  match="//PAIR">

       <!-- Create variables to  hold documents pointed to from index.xml -->
       <xsl:variable  name="article" select="document(ARTICLE)"/>
       <xsl:variable  name="category" select="document(CAT)"/>

       <!-- Create temporary  tree with entire article and
descendents of the categories element  -->
       <xsl:variable  name="temp">
           <xsl:apply-templates  select="$article|$category//categories"/>
        </xsl:variable>

        <!-- Creates output  directories and filenames -->
       <xsl:variable  name="doi_filename">
            <xsl:text>/projects/working/</xsl:text><xsl:value-of
select="//FOLDER"/><xsl:text>/</xsl:text><xsl:value-of
select="substring-before($category//doi, '/')"/>
           <xsl:value-of  select="substring-after($category//doi,
'/')"/><xsl:text>.xml</xsl:text>
        </xsl:variable>

       <!-- Output document with  doi as filename -->
       <xsl:result-document  href="$doi_filename">
           <xsl:apply-templates  select="$temp"/>
        </xsl:result-document>
   </xsl:template>

  <!-- output category elements  as children of
article-meta/categories element  -->
   <xsl:template  match="//article-meta//categories">
        <xsl:copy>
          <xsl:apply-templates
select="//article-meta/following-sibling::categories//category"/>
        </xsl:copy>
    </xsl:template>

    <!-- Drop all category  elements -->
   <xsl:template  match="/categories"/>

    <!-- Identity Transform  -->
   <xsl:template  match="node()|@*">
        <xsl:copy>
           <xsl:apply-templates  select="@*"/>
            <xsl:apply-templates/>
        </xsl:copy>
    </xsl:template>
</xsl:stylesheet>

Index.xml
<INDEX>
    <WORKFOLDER>C:</WORKFOLDER>
    <FOLDER>Playground</FOLDER>
    <PAIRS>
        <PAIR>
            <ARTICLE>article1.xml</ARTICLE>
            <CAT>cat1.xml</CAT>
        </PAIR>
        <PAIR>
            <ARTICLE>article2.xml</ARTICLE>
            <CAT>cat2.xml</CAT>
        </PAIR>
    </PAIRS>
</INDEX>

Cat1.xml:
<article-category>
                <doi>10.9999/0000000000000</doi>
                <categories>
                               <category>Jungle Gyms</category>
                                <category>Swing Sets</category>
                                <category>Monkey Bars</category>
                                <category>Slides</category>
                </categories>
</article-category>


Article1.xml <root doi="10.9999/0000000000000" type="journal"> <header> <journal-meta> <title>Journal of Playgrounds</title> <ISSN>0000-000x</ISSN> <volume>1</volume> <issue>4</issue> <date> <year>2003</year> <month>June</month> </date> <publication> <name>Me Enterprises</name> <location>Springfield, Simpson State</location> </publication> </journal-meta> <article-meta> <title>Playground Equipment</title> <subtitle>Alternative Methods and Conclusions</subtitle> <author> <person> <firstname>Bob</firstname> <middle>J.</middle> <surname>Smith</surname> <aff>University of Pennsylvania</aff> </person> </author> <startpage>98</startpage> <finishpage>119</finishpage> <categories/> </article-meta> </header> <body> </body> <references> </references> </root>

Current Thread