RE: Variable Substitution In A Select Statement
David, First, a big "Thanks!" for your kind and timely help! Talk about a quick response. Here is my solution: <xsl:variable name="expression" select="concat($Axpath_new, '/@id')" /> <xsl:apply-templates select ="$FileA/saxon:evaluate($expression)" /> The $FileA variable references an external document and with my new gained knowledge of 'saxon.evaluate()' I'm able to locate the proper @id along the Xpath specified in $Axpath. Cheers, Raymond Lillibridge -----Original Message----- From: David Carlisle [mailto:davidc@xxxxxxxxx] Sent: Tuesday, May 24, 2011 9:22 AM To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: Re: Variable Substitution In A Select Statement On 24/05/2011 14:07, Raymond Lillibridge wrote: > xsl-list Members, > > Using Saxon-PE 188.8.131.52J from Saxonica (XSLT 2.0): > > The following template matches on the specified @id in $FileA. Just what I need. > > <xsl:apply-templates > select="$FileA/book/level1/level2/section/@id" /> > > However, if I have a variable, $Axpath_new, valued at "book/level1/level 2/section", the following template returns nothing: > > <xsl:apply-templates select ="$FileA/$Axpath_new/@id" /> > > Testing a multitude of methods, I could never get a variable to work in the select statement. > After much studying about how to make the template work properly, I > read that I could try using the extension function node-set(). > Further research stated that my free version of Saxon9 doesn't include > those extensions but the Saxon9pe version does. So, I purchased a > copy of Saxon9pe and installed it yesterday. (Also, I believe I read > that if I was using XSLT 2.0, I wouldn't need to use the node-set() > function.) > > Any way, it seems like such a simple thing but I'm at a loss, and I'm asking for your kind assistance. > actually having evaluation at run time is quite a big thing 9and not available in most languages) as it means having all the parsing machinery available which is not normally in the compiled code. If you have a string x with value " + 2" in C or java or fortran or ... you can't just go 3 x and have it expand to 3 + 2 and evaluate to 5. However for some reason it's quite common to expect that xslt has this feature. to use saxon:evaluate you need to declare the saxon extension namespace then something like saxon:evaluate(concat('$FileA,'/',$Axpath_new.'/@id')) ie build up the xpath you want to evaluate as a single string then pass it to the function. You didn't say why you are needing evaluation though, are you picking up the xpaths from an external file? otherwise it may be better to store the sequence of nodes selected by book/level1/level 2/section in a variable, rather than the string "book/level1/level 2/section" then you could just do $variable/'id to select the id attributes. David David ________________________________________________________________________ The Numerical Algorithms Group Ltd is a company registered in England and Wales with company number 1249803. The registered office is: Wilkinson House, Jordan Hill Road, Oxford OX2 8DR, United Kingdom. This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. ________________________________________________________________________
PURCHASE STYLUS STUDIO ONLINE TODAY!
Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!
Download The World's Best XML IDE!
Accelerate XML development with our award-winning XML IDE - Download a free trial today!
Subscribe in XML format