That seems to be throwing the following exception:
System.Xml.Xsl.XslTransformException: To use a result tree fragment in a path
expression, first convert it to a node-set using the msxsl:node-set() function.
I don't think you can create a variable variable (so to speak). What I've done in the past is create two variables and pass them as an xsl param to an xsl template. So in the call-template, I do an xsl choose to determine which of the two variables I should pass.
The problem is probably that your NewsItems variable content is not interpreted as xml. Possible the solution would be to replace variable value-of by copy-of.
BTW, the error it throws is slightly off. It is actually telling you to use the msxml:node-set() function. If you are trying to cycle through the NewsItems later you may need to do this to tell the XML it is working with a node-set:
I am having the same issue. I want to get the root node of a content tree at level 1 but if the current page is at level 1 i want to get that. here is my code:
I was tearing my hair out with this one too, but here's a solution that works (thanks to Lee Kelleher):
<xsl:variable name="nodes">
<xsl:choose>
<xsl:when test="$collegeId != -1">
<!-- Grab all news items that have been tagged with this school/college -->
<root>
<xsl:copy-of select="$currentPage/ancestor::Homepage[@isDoc]/NewsContainer[@isDoc]/DateFolder[@isDoc]/DateFolder[@isDoc]/NewsItem[@isDoc and ./schoolsColleges/XPathCheckBoxList/nodeId = $collegeId]"/>
</root>
</xsl:when>
<xsl:otherwise>
<!-- Grab all news items that have been flagged to display on home page -->
<root>
<xsl:copy-of select="$currentPage/ancestor::Homepage[@isDoc]/NewsContainer[@isDoc]/DateFolder[@isDoc]/DateFolder[@isDoc]/NewsItem[@isDoc and appearsOnHomepage = 1]"/>
</root>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="matchedNodes" select="msxml:node-set($nodes)/root/*"/>
Things to note:
within the choose branches, I'm wrapping the results of <xsl:copy-of> (not value-of) with a <root></root> node. This means that my result will have a single root node, e.g. <root><item1/><item2/></root> instead of <item1/><item2/>.
I'm calling msxml:node-set to convert my result to a proper node set. This works now because there is a single root element in $nodes (that I added).
I'm using msxml:node-set($nodes)/root/* to return all nodes below my root node into $matchedNodes.
I've just had to return to a v4.7.1 site do an update and after a long time away from XSLT I hit this issue again. The funny thing it I keep finding my own threads when searching for these historic issues but thankfully @David provided me with the answer again! :) I owe you a beer at the UK Festival this year if you're attending?
Haha, glad you're still getting value from that post @Simon, I know that I came back to it again and again with XSLT sites. Yes I'll be at the UK Fest - see you there :)
To use a result tree fragment in a path expression, first convert it to a node-set using the msxsl:node-set() function
My XSLT is by no means great and I am struggling with this one so would appreciate some pointers please if anyone can assist:
I have the following snippet of XSLT:
That seems to be throwing the following exception:
I don't think you can create a variable variable (so to speak). What I've done in the past is create two variables and pass them as an xsl param to an xsl template. So in the call-template, I do an xsl choose to determine which of the two variables I should pass.
Would love to know if there's a better solution!
The problem is probably that your NewsItems variable content is not interpreted as xml. Possible the solution would be to replace variable value-of by copy-of.
You could check out this thread also.
>Tommy
Sebastiaan, I don't believe you can change the value of a variable after it has been set but what I am doing is trying determine what value to set.
Unfortunately no joy with your solution either Tommy
Simon, I just tried your initial code, and it seems to work without errors on my side - just with a
added.
Hope you work it out.
>Tommy
I am getting this too, and pulling my hair out!
I can't recreate this one and looking at it, it looks like it "should" work as all you are doing is treating your first variable as a string.
Might be worth coercing it to a string using string():
BTW, the error it throws is slightly off. It is actually telling you to use the msxml:node-set() function. If you are trying to cycle through the NewsItems later you may need to do this to tell the XML it is working with a node-set:
How did you solve this? I'm getting the same error...
Thx!
Edited :
Got this working, thanks to webangelo !
Hi there,
I have tried the that code
It is fixing Error while saving time but its is not retrivin my node-set....
is any one can help me please.......
I am having the same issue. I want to get the root node of a content tree at level 1 but if the current page is at level 1 i want to get that. here is my code:
now i get no error but i get no content either
well, i found a way around it. i created a template that gets called in the choose item instead of setting a value:
I was tearing my hair out with this one too, but here's a solution that works (thanks to Lee Kelleher):
Things to note:
within the choose branches, I'm wrapping the results of <xsl:copy-of> (not value-of) with a <root></root> node. This means that my result will have a single root node, e.g. <root><item1/><item2/></root> instead of <item1/><item2/>.
I'm calling msxml:node-set to convert my result to a proper node set. This works now because there is a single root element in $nodes (that I added).
I'm using msxml:node-set($nodes)/root/* to return all nodes below my root node into $matchedNodes.
Hope that helps someone!
David
@David
It does :-)
@David you saved my night!
I've just had to return to a v4.7.1 site do an update and after a long time away from XSLT I hit this issue again. The funny thing it I keep finding my own threads when searching for these historic issues but thankfully @David provided me with the answer again! :) I owe you a beer at the UK Festival this year if you're attending?
Haha, glad you're still getting value from that post @Simon, I know that I came back to it again and again with XSLT sites. Yes I'll be at the UK Fest - see you there :)
is working on a reply...