[xsl] Using an xsl:variable within an xsl:apply-templates select

Subject: [xsl] Using an xsl:variable within an xsl:apply-templates select
From: "Timothy M. Lebo" <tlebo@xxxxxxxxx>
Date: Tue, 9 Sep 2003 20:41:34 -0500

I am calling the following template with an Xpath expression to limit
the number of element nodes that are processed from an input document.
While processing these nodes, I want to process the current node and
each element that the context node refers to (and nothing more). 

For example, let thing 1 be the node set that this template is applied
to. This template will process thing 1 and thing 2, but not thing 3
because it is not referred to by thing 1.

Sample input:
<thing rdf:ID="1">
 <likes rdf:resource="2"/>

<thing rdf:ID="2">
 <likes rdf:resource="3"/>

<thing rdf:ID="3">
 <likes rdf:resource="4"/>

My question: Is it permitted to use an xsl:variable within the
xsl:apply-templates select attribute as I do below? The value-of count
is returning 0 when there exists a thing with an rdf:ID that matches the
contents of the myIDREF variable. Could my Xpath expression be

Also: I am not using the id() or key functions because I would think
that my described technique should work. If the either technique is
applicable and cleaner, I would appreciate the advice.

   <xsl:template match="thing" mode="gather">
     <!-- Process current node -->
     <xsl:apply-templates select="." mode="process"/>
     <!-- Process nodes that I refer to -->
     <xsl:for-each select="*/@resource">
       <xsl:variable name="myIDREF" select="."/>
       <xsl:value-of select="$myIDREF"/>
       <xsl:value-of select="count(//thing[@rdf:ID=$myIDREF])"/>
       <xsl:apply-templates select="//thing[@rdf:ID=$myIDREF]"
mode="process"/> <!-- HERE -->

   <xsl:template match="thing" mode="process">
     	<!-- Do stuff, but don't apply-templates to things I refer to

The rdf namespace is defined and matches that of the input namespace


Timothy M. Lebo
Research Associate
Smart Information Flow Technologies

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

Current Thread