Subject: RE: [xsl] Variable Substitution In A Select Statement From: Raymond Lillibridge <RLillibridge@xxxxxxxxxxxx> Date: Tue, 24 May 2011 16:31:00 +0000 |
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: [xsl] Variable Substitution In A Select Statement On 24/05/2011 14:07, Raymond Lillibridge wrote: > xsl-list Members, > > Using Saxon-PE 9.3.0.5J 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[2]/level2[4]/section[2]/@id" /> > > However, if I have a variable, $Axpath_new, valued at "book/level1[2]/level 2[4]/section[2]", 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[2]/level 2[4]/section[2] in a variable, rather than the string "book/level1[2]/level 2[4]/section[2]" 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. ________________________________________________________________________
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Variable Substitution In , David Carlisle | Thread | Re: [xsl] Variable Substitution In , David Carlisle |
Re: [xsl] evaluate rendered text le, Eliot Kimber | Date | Re: [xsl] Variable Substitution In , David Carlisle |
Month |