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

node-set returning functions and their applications

Subject: node-set returning functions and their applications
From: Nic Ferrier <nferrier@xxxxxxxxxxxxxxxxxxxx>
Date: 01 Oct 2003 20:52:56 +0100
set returning functions
A colleague and I were working on the following problem: we want to
pass a comma separted list of values to a stylesheet and have the
stylesheet extract bits of the input xml based on the values. 

We knew we could use str:split to find the values and then create
templates from them, something like this:


  <xsl:param name="id_list">1,2,3,4</xsl:param>

  <xsl:template match="/">
     <xsl:for-each select="str:split($id_list, ',')">

        <xsl:variable name="the_id" select="." />

        <xsl:apply-templates select="//el[@id = $the_id]" />

     </xsl:for-each>
  </xsl:template>

But we just couldn't get it to work. The node-set returned by the
xpath expression in the inner apply-templates was empty.

We scratched our heads for some time (and went down several blind
alleys) before realising that the document context within the
for-each is different to the context outside it.

The fix to our problem is to take a node-set pointer from the main
document into the for-each with us:

  <xsl:template match="/">

     <xsl:variable name="the_document" select="//el" />

     <xsl:for-each select="str:split($id_list, ',')">

        <xsl:variable name="the_id" select="." />

        <xsl:apply-templates select="$the_document[@id = $the_id]" />

     </xsl:for-each>
  </xsl:template>


We hope that Google finds this and that other people can find it in
Google.


Nic Ferrier
http://www.tapsellferrier.co.uk


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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

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.
Email
First Name
Last Name
Company
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.