xsl-list
[Top] [All Lists]

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

2004-06-18 11:47:08
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[(_at_)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



<Prev in Thread] Current Thread [Next in Thread>