Recursing on top-level elements

Subject: Recursing on top-level elements
From: "Jan Thunqvist" <jan.thunqvist@xxxxxxxxxxx>
Date: Thu, 30 Mar 2000 09:36:07 +0200
Hi,

How can I recurse on top-level context elements while doing a for-each loop
further down the structure?

Example XML:

<test>
   <foo id=1/>
   <foo id=3/>
   <bar>
      <baz id=1/>
      <baz id=2/>
      <baz id=3/>
      <baz id=4/>
   </bar>
</test>

Now, while in my for-each on /test/bar/baz, I want to do something if the id
attribute on a baz element exists in any of the foo elements. My XSL now
looks like this:

<xsl:template match="/">
   <xsl:for-each select="test/bar/baz">
      <xsl:choose>
         <xsl:when test=".[@id = /test/foo/@id]">
            <!-- Do something -->
         </xsl:when>
         <xsl:otherwise>
            <!-- Do something else -->
         </xsl:otherwise>
      </xsl:choose>
   </xsl:for-each>
</xsl:template>

This works for baz elements that have the same id as the first foo element
(id=1), but not for the baz with id=3.

Suggestions anyone?

/Jan


***************************************************
Jan Thunqvist
e-mail: jan.thunqvist@xxxxxxxxxxx

Technia AB
Box 1141
S-164 22 KISTA, Sweden
Tel: +46-(0)8-477 24 00
Fax: +46-(0)8-477 24 24
WWW: http://www.technia.com



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


Current Thread