This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Recursing on top-level elements


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@technia.com

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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]