[xsl] gather all similar elements in different docs

Subject: [xsl] gather all similar elements in different docs
From: Robert Koberg <rob@xxxxxxxxxx>
Date: Fri, 9 Jan 2009 16:48:39 -0500
Hi, (using saxon9)

I have a few pages that each contain a table of definitions. The tables look like (they do not have a namespace):

  <table border="0" cellspacing="0">
      <tr>
         <td>
            <p>absenteeism</p>
         </td>
         <td>
            <p>frequent or habitual absence from school</p>
         </td>
      </tr>
....

Can I gather up all of the TR elements, like my defs variable below (or some other way) and apply-templates on them (while sorting)? The stylesheet below causes an error "Too many nested apply-templates calls. The stylesheet may be looping." at the <xsl:apply-templates select="$defs">

What am I doing wrong here?

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="2.0">

<xsl:variable name="defs">
<xsl:copy-of select="doc('lsb/content/glossary-1.1.1.xml')//tr"/>
<xsl:copy-of select="doc('lsb/content/modules-1-glossary.xml')// tr"/>
<xsl:copy-of select="doc('lsb/content/modules-2-glossary.xml')// tr"/>
<xsl:copy-of select="doc('lsb/content/modules-3-glossary.xml')// tr"/>
<xsl:copy-of select="doc('lsb/content/modules-4-glossary.xml')// tr"/>
</xsl:variable>


  <xsl:template match="/">
    <glossentries>
      <xsl:apply-templates select="$defs">
        <xsl:sort select="normalize-space(td[1]/p/text())"/>
      </xsl:apply-templates>
    </glossentries>
  </xsl:template>

<xsl:template match="tr">
<xsl:variable name="term" select="normalize-space(td[1]/p/ text())"/>
<xsl:variable name="file-name" select="translate($term, ' ', '-')"/>
<glossentry file-name="{$file-name}">
<term>
<xsl:value-of select="$term"/>
</term>
<definition>
<xsl:copy-of select="td[2]/*"/>
</definition>
</glossentry>
</xsl:template>


</xsl:stylesheet>

thanks,
-Rob

Current Thread