[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Not a nested for loop.

Subject: Re: Not a nested for loop.
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Wed, 16 Jan 2002 14:28:23 +0000
nested for loop r
Hi Dave,

> I need to loop through each of the main input document records (r
> elements) and if r/cat-num is any one of the values of the external
> file, /bk/n then I need to copy the r element and contents through
> to the output.
> Can xslt2.0 help with this form of filtering?

Of course you can it currently with:

<xsl:copy-of select="r[cat-num = document('external.xml')/bk/n]" />

But it's not particularly efficient.

For something more efficient you could use a key. In XSLT 1.0 you
would do:

<xsl:key name="nums" match="bk/n" use="." />

<xsl:for-each select="r">
  <xsl:variable name="r" select="." />
  <xsl:for-each select="document('external.xml')">
    <xsl:if test="key('nums', $r/cat-num)">
      <xsl:copy-of select="$r" />

In XSLT 2.0 you can do:

<xsl:key name="nums" match="bk/n" use="." />

<xsl:for-each select="r">
  <xsl:if test="document('external.xml')
                  /key('nums', current()/cat-num)">
    <xsl:copy-of select="." />

Or you could do:

<xsl:key name="nums" match="bk/n" use="." />

<xsl:copy-of select="for $r in r
                     return if (document('external.xml')
                                  /key('nums', $r/cat-num))
                            then $r
                            else ()" />



Jeni Tennison

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

Current Thread
  • Not a nested for loop.
    • DPawson - Wed, 16 Jan 2002 08:59:41 -0500 (EST)
      • Jeni Tennison - Wed, 16 Jan 2002 09:26:39 -0500 (EST) <=
      • Michael Kay - Wed, 16 Jan 2002 09:58:23 -0500 (EST)
      • <Possible follow-ups>
      • DPawson - Wed, 16 Jan 2002 10:27:24 -0500 (EST)


Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
First Name
Last Name
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.