net_susan
asked on
XSL Variables
I'm trying to create a variable in my XSL stylesheet.
This line works:
<xsl:variable name="Rows" select="/dsQueryResponse/S ome_List/R ows/Row[no rmalize-sp ace(@Page) = 'Home']"/>
What I want to do is something like this:
<xsl:variable name="Susan">Some_List</xs l:variable >
<xsl:variable name="Rows" select="/dsQueryResponse/@ Susan/Rows /Row[norma lize-space (@Page) = 'Home']"/>
What am I doing wrong?
This line works:
<xsl:variable name="Rows" select="/dsQueryResponse/S
What I want to do is something like this:
<xsl:variable name="Susan">Some_List</xs
<xsl:variable name="Rows" select="/dsQueryResponse/@
What am I doing wrong?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
What does this do:
*[name()
*[name()
[] is the indication of a "predicate", a special condition on eg. an element
* is a wild-card for element nodes
name() is the XPath function that returns the name of the node
*[name() = $Susan]
is the element that has a name equal to the content of variable $Susan
* is a wild-card for element nodes
name() is the XPath function that returns the name of the node
*[name() = $Susan]
is the element that has a name equal to the content of variable $Susan
ASKER
You rock.
If you would, I'd like to know if these two options are kosher (they both seem to work), but either way you get the points because you answered my question, and it works!.
Option One:
<Xsl>
<xsl:variable name="Susan">Some_List</xs l:variable >
</Xsl>
<xsllink>http://somepage.com/SomeTemplate.xsl</xsllink>
Option Two:
<xsllink>http://somepage.com/SomeTemplateWithVar.xsl</xsllink>
<xsllink>http://somepage.com/SomeTemplate.xsl</xsllink>
Contents of SomeTemplateWithVar.xsl:
<xsl:stylesheet xmlns:xs="deleted for space">
<xsl:variable name="Susan">Some_List</xs l:variable >
</xsl:stylesheet>
If you would, I'd like to know if these two options are kosher (they both seem to work), but either way you get the points because you answered my question, and it works!.
Option One:
<Xsl>
<xsl:variable name="Susan">Some_List</xs
</Xsl>
<xsllink>http://somepage.com/SomeTemplate.xsl</xsllink>
Option Two:
<xsllink>http://somepage.com/SomeTemplateWithVar.xsl</xsllink>
<xsllink>http://somepage.com/SomeTemplate.xsl</xsllink>
Contents of SomeTemplateWithVar.xsl:
<xsl:stylesheet xmlns:xs="deleted for space">
<xsl:variable name="Susan">Some_List</xs
</xsl:stylesheet>
both options are OK
you might consider to make this a parameter instead of a variable
<xsl:param name="Susan">Some_List</xs l:param>
this would allow you to pass the value in from outside
In that case I prefer to keep the parameter in the main XSL
cheers
Geert
you might consider to make this a parameter instead of a variable
<xsl:param name="Susan">Some_List</xs
this would allow you to pass the value in from outside
In that case I prefer to keep the parameter in the main XSL
cheers
Geert
ASKER
Darn, this isn't working at all. Thought it was. Closed it too soon.
You must have invented your own syntax for including xsl files
(I imagined that you were processing this first in order to create real XSLT)
Here is the correct syntax
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:variable name="Susan">Some_List</xs l:variable >
<xsl:include href="http://somepage.com/SomeTemplate.xsl" />
...
</xsl:stylesheet>
(I imagined that you were processing this first in order to create real XSLT)
Here is the correct syntax
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:variable name="Susan">Some_List</xs
<xsl:include href="http://somepage.com/SomeTemplate.xsl" />
...
</xsl:stylesheet>
ASKER
I don't know why that's not working for me. I did want to call the vars from outside the stylesheet, but I guess I wasn't clear about that. That was my whole point of doing it.
Changing this <xsl:variable name="Susan">Some_List</xs l:variable > to this
<xsl:param name="Susan">Some_List</xs l:param> completely breaks it, even inside the sheet. :(
Still, you have gotton me closer I'm sure.
Changing this <xsl:variable name="Susan">Some_List</xs
<xsl:param name="Susan">Some_List</xs
Still, you have gotton me closer I'm sure.
That means that the xsl:variable is at a location where param is not allowed
If you want to pass in a parameter,
it should be a top level element
As in my example, move the param to right under the stylesheet element
If you want to pass in a parameter,
it should be a top level element
As in my example, move the param to right under the stylesheet element
ASKER
Okay, thank you. It is working. I appreciate you coming back even after I awarded points. I'll probably post another related question later.
so you need to do a string compare, matching the name
you access variables with a $, not with a @
cheers
Geert