[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

RE: [xsl] recursion with xsl:apply-templates


Subject: RE: [xsl] recursion with xsl:apply-templates
From: "Andrew Welch" <AWelch@xxxxxxxxxxxxxxx>
Date: Wed, 27 Aug 2003 12:32:19 +0100

> Anyway, my primary problem remains. Any ideas?
> Volker.

I would use a variable here, then query that for each id.

Something like:

<xsl:variable name="indexToIDs">
  <xsl:for-each select="//*[@index]">
    <xsl:variable name="pos" select="position()"/>
    <entry genid="{generate-id()}"
id="{/transformation/id_list/id[$pos]}"/>
  </xsl:for-each>
</xsl:variable> 

Which will give you an RTF of elements like this:

<entry genid="abc" id="2003..."/>
<entry genid="foo" id="2004..."/>

Then you should perform an identity transform on your source, with an
extra template handling elements with @index.

In that template query the rtf (or more to the point, query a variable
that is a nodeset of the rtf) using the generated id of the current
element for its id, and construct your output how you want it, something
like:

The identity transform:

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

The template to handle the special case:

<xsl:template match="*[@index]">
  <xsl:variable name="genid" select="generate-id()"/>
  <xsl:copy>
    <xsl:copy-of select="$indexToIDsNodeSet/entry[@genid =
$genid]/@id"/>
    <xsl:apply-templates select="@*|node()"/>
  </xsl:copy>
</xsl:template>

A template to supress @index
<xsl:template match="@index"/>


cheers
andrew

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



Current Thread