freelanceprogrammers.org Forum Index » XML / XSL
Trouble with Variables
Joined: 10 Mar 2005
Posts: 11
Trouble with Variables
First, I would like to thank everyone here for the immense
help that was provided to me with my previous problem
regarding UTF characters.
The problem was solved --- thanks to the help I got in
this group.
Now, another problem has reared it`s head -- this one
having to do with variables.
I declare a variable named "TopAnchor" to act as the
relative-location of the main directory of a sub-site.
Problem is --- it seems like XSL allows me to output
the value of a variable OUTSIDE of the tags as part of
the actual text with the following syntax:
<xsl:value-of select="$TopAnchor"/>
But I don`t seem to be able to do the same *within*
tags -- which is what I need to do.
For example, the following won`t work:
[<a href="$TopAnchor/index.html"><a href="$ImageAnchor/home.gif"></a>]
because in this case, it doesn`t displace the
text "$TopAnchor" with the value of the variable
"TopAnchor" --- but rather, interprets it as
just any old text --- same problem with
"$ImageAnchor".
My question is this --- is there any way
*around* this limitation of XSL?
Thanks,
Adam
Joined: 13 Jun 2003
Posts: 10
Trouble with Variables
At 2006-03-27 16:20 -0500, Adam Ophir Shapira wrote:
>I declare a variable named "TopAnchor" to act as the
>relative-location of the main directory of a sub-site.
>
>Problem is --- it seems like XSL allows me to output
>the value of a variable OUTSIDE of the tags as part of
>the actual text with the following syntax:
><xsl:value-of select="$TopAnchor"/>
>
>But I don`t seem to be able to do the same *within*
>tags -- which is what I need to do.
>
>For example, the following won`t work:
>[<a href="$TopAnchor/index.html"><a href="$ImageAnchor/home.gif"></a>]
Right ... because in XSLT a result element`s attribute`s value is put
out verbatim character by character until it hits an attribute value
template indicated by a left curly brace. The content to the right
curly brace is interpreted as an XPath expression, and is evaluated
like "value-of". Then, it continues copying more characters until it
hits another attribute value template.
>because in this case, it doesn`t displace the
>text "$TopAnchor" with the value of the variable
>"TopAnchor" --- but rather, interprets it as
>just any old text --- same problem with
>"$ImageAnchor".
>
>My question is this --- is there any way
>*around* this limitation of XSL?
"limitation"? What if I wanted to put out "$TopAnchor" as my attribute?
The following will work for you:
[<a href="{$TopAnchor}/index.html"><a href="{$ImageAnchor}/home.gif"></a>]
Note this is a common misconception by my students before taking my
XSL courses ... the designers assumed that the attribute text would
usually be verbatim, so they added a facility to engage a "value-of"
in an attribute ... not the other way around.
And yours is an example of mixing both expressions and verbatim text.
If you want an actual curly brace, then use two to get one. It was
probably thought that curly braces were not popularly used ... but
then this predates Ant ... writing XSLT for an Ant Script is fun
having to deal with the curlies ... you get things like:
message="${{{$varname}}}"
in XSLT to get:
message="${abc}"
in the resulting Ant script.
I hope this helps.
. . . . . . . . . . . Ken
--
Registration open for XSLT/XSL-FO training: Wash.,DC 2006-06-12/16
World-wide on-site corporate, govt. & user group XML/XSL training.
G. Ken Holman mailto:gkholman@...
Crane Softwrights Ltd. http://www.CraneSoftwrights.com/x/
Box 266, Kars, Ontario CANADA K0A-2E0 +1(613)489-0999 (F:-0995)
Male Cancer Awareness Aug`05 http://www.CraneSoftwrights.com/x/bc
Legal business disclaimers: http://www.CraneSoftwrights.com/legal
All times are GMT
Page 1 of 1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Freelace Website Designer - Customer web design and software building.
China Wholesale - Electronics Products
Character Studio - Tutorials and Help
China Wholesale - Electronics Products
Character Studio - Tutorials and Help







