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

Re: How to copy parts of an var into another ?

Subject: Re: How to copy parts of an var into another ?
From: david_n_bertoni@xxxxxxxxxx
Date: Fri, 18 Jun 2004 11:47:08 -0700
copy var
> Hello List,
>
> I have a var:
>
> <xsl:variable name="foo">
>            <item name="a item">
>                        <value>1</value>
>            </item>
>            <item name="another item">
>                        <value>2</value>
>            </item>
> </xsl:variable>

In XSLT 1.0, you cannot search inside a result tree fragment without using
your processor's node-set extension function.  A better way to do this is
to put the data in another document and use the document() function to
parse the document, storing the result in a global variable:

   <xsl:variable name="table" select="document('mytable.xml')" />

If you don't want to use a second document, put the data in the stylesheet,
but in a top-level element in an application-specific namespace:

   <foo:table xmlns:foo="http://www.foo.com/tables">
             <item name="a item">
                         <value>1</value>
             </item>
             <item name="another item">
                         <value>2</value>
             </item>
   </foo:table>

Then, use the document function to select the table into a variable:

   <xsl:variable name="table" select="document('')/foo:table"
   xmlns:foo="http://www.foo.com/tables" />

You can then use XPath expressions to find what you need:

   <xsl:for-each select="$table/item[@name='a item']">
   ...
   </xsl:for-each>

If you take a look at Dave Pawson's XSL FAQ, you'll find more information
about these techniques:

   http://www.dpawson.co.uk/xsl/sect2/N4995.html

Dave


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.