RE: [xsl] Binding a variable within a "value-of select"

Subject: RE: [xsl] Binding a variable within a "value-of select"
From: "Khorasani, Houman" <houman_khorasani@xxxxxxxxxxxxxx>
Date: Tue, 25 Oct 2005 14:39:07 +0100
Antsnio, it works. Cheers!
David, also many thanks for the detailed explanation.

It works and I learned something new. :)

Kind regards
Houman




-----Original Message-----
From: David Carlisle [mailto:davidc@xxxxxxxxx]
Sent: 25 October 2005 13:52
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: [xsl] Binding a variable within a "value-of select"


> I was thinking to use the { } as a solution.

{} is never Xpath syntax, so

<xsl:value-of select="WBSLServiceData/{$addorDef}/PostCode"/>
<xsl:value-of select="{WBSLServiceData/$addorDef/PostCode}"/>


are both syntax errors

<xsl:value-of select="WBSLServiceData/$addorDef/PostCode"/>

is legal syntax and if $addorDef contained a node set this would
evaluate to some value, but you say that it
contains a ___string___ so the above is equivalent to


<xsl:value-of select="WBSLServiceData/'def'/PostCode"/>

which is a type error you can't use a string in the middle of an Xpath.

variables hold values, not fragments of Xpath syntax. If you have a
variable foo in C (or Java or pretty much any other language you choose)
that contained a string such as " + 1" you wouldn't expect to be able to
use
 2 foo
to expand to
2 + 1
and so evaluate to 3.

variables in XSL are (a bit) like variables in C they are not like C
preprocessor macros.

If you have a variable that contains Xpath syntax then you need an
extension function that makes an Xpath parser available at run time.
(eg saxon:evaluate) or if the variable is just a single element name the
FFFFAQ answer is
WBSLServiceData/*[name()=$addorDef]/PostCode

David

________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

Current Thread