XSLT - using NodeSet() on a variable value passed from a template

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi all,
I have a template which I call (xsl:call-template) where I pass in a parameter and then within the template I have some logic (xsl:choose) to determine the value of the XML nodes that I pass out out of the template in a variable. Below is the template...

<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; template <span style="color:Red; name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; TemplateName<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; param <span style="color:Red; name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Value<span style="color:Black; " <span style="color:Blue; />

<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; variable <span style="color:Red; name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; NodeSetVariable<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; choose<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; when <span style="color:Red; test<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; number($Value) = 1<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Score<span style="color:Blue; >A<span style="color:Blue; </<span style="color:#A31515; Score<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Description<span style="color:Blue; >Text value<span style="color:Blue; </<span style="color:#A31515; Description<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; when<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; when <span style="color:Red; test<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; number($Value) = 2<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Score<span style="color:Blue; >B<span style="color:Blue; </<span style="color:#A31515; Score<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Description<span style="color:Blue; >Text value<span style="color:Blue; </<span style="color:#A31515; Description<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; when<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; when <span style="color:Red; test<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; number($Value) = 3<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Score<span style="color:Blue; >C<span style="color:Blue; </<span style="color:#A31515; Score<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; Description<span style="color:Blue; >Text value<span style="color:Blue; </<span style="color:#A31515; Description<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; when<span style="color:Blue; >
...
<span style="color:Blue; </<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; choose<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; variable<span style="color:Blue; >

<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; value-of <span style="color:Red; select<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; msxsl:node-set($NodeSetVariable)<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; </<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; template<span style="color:Blue; >
[/code]

I then call this template in which I store the returned value (supposed to be a NodeSet variable) into a variable (here named CommonRating)...

<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; variable <span style="color:Red; name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; CommonRating<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; call-template <span style="color:Red; name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; TemplateName<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; with-param <span style="color:Red; name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Value<span style="color:Black; " <span style="color:Red; select<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; /value<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; </<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; call-template<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; variable<span style="color:Blue; >
[/code]

I then try to use this variable to extract the values which was assigned to the nodes in the template (named TemplateName).

<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; value-of <span style="color:Red; select<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; msxsl:node-set($CommonRating)/Score<span style="color:Black; "<span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; text<span style="color:Blue; >-<span style="color:Blue; </<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; text<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; value-of <span style="color:Red; select<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; msxsl:node-set($CommonRating)/Description<span style="color:Black; "<span style="color:Blue; />
[/code]

I have included the following in the XSLT stylesheet declaration at the top of the page...
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
but I still cant seem to get the NodeSet values when using, msxsl:node-set($CommonRating)/Score.
Can anyone see where I may be going wrong?
Thanks in advance. <hr class="sig Tryst

View the full article
 
Back
Top