Re: [xsl] Variable Substitution In A Select Statement

Subject: Re: [xsl] Variable Substitution In A Select Statement
From: David Carlisle <davidc@xxxxxxxxx>
Date: Tue, 24 May 2011 14:21:53 +0100
On 24/05/2011 14:07, Raymond Lillibridge wrote:
xsl-list Members,

Using Saxon-PE 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
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.



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