It gives me this error: 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.
It's because in the second version you're using a value-of instruction to assign to the $sliderNode variable - value-of always returns a string, and you need a nodeset (a single node is still a nodeset). You can use copy-of to get the node instead - but you still need to create a nodeset from the created variable.
There's a built-in extension function available for it that you can use like this:
Help! - Xslt newbie
Can someone please explain why this piece of code works:
but this piece of code doesn't.
It gives me this error:
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.
<xsl:variable name="maxItems" select="number(6)" />
<msxsl:script language="JavaScript" implements-prefix="lk">
function Random(r) { return Math.ceil(Math.random()*r); }
</msxsl:script>
<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:param name="currentPage"/>
<xsl:template match="/">
<xsl:variable name="sliderNode">
<xsl:choose>
<xsl:when test="$currentPage/@id = '1206'">
<xsl:value-of select="umbraco.library:GetXmlNodeById(1280)" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="umbraco.library:GetXmlNodeById(1279)" />
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:for-each select="$sliderNode/child::Testimonial">
<xsl:sort select="lk:Random($maxItems)" order="descending" />
<xsl:if test="position() <= $maxItems">
<p><span class="regular-text"><xsl:value-of select="testimonialText" disable-output-escaping="yes"/>
<span class="italic-text"><xsl:value-of select="testimonialName" disable-output-escaping="yes"/><br />
<xsl:value-of select="testimonialPosition" disable-output-escaping="yes"/><br />
<xsl:value-of select="testimonialCompany" disable-output-escaping="yes"/><br /><br /></span>
<a href="#">More Testimonials</a></span></p>
</xsl:if>
</xsl:for-each>
</xsl:template>
Any help is appreciated!
Hi Wes,
It's because in the second version you're using a value-of instruction to assign to the $sliderNode variable - value-of always returns a string, and you need a nodeset (a single node is still a nodeset). You can use copy-of to get the node instead - but you still need to create a nodeset from the created variable.
There's a built-in extension function available for it that you can use like this:
(msxsl: may need to be msxml: depending on which is used at the top of your stylesheet where it would say xmlns:msxsl="urn:schemas-...")
/Chriztian
Thanks for the quick reply Chriztian!
That's stopped the error from occuring but it's not actually returning any data on screen now.
This is what I have:
I think it's an issue with the choose.
$pageID definitely returns the correct ID, the otherwise doesn't seem to work either.
I'm not sure how best to debug it either, I've tried to output text from the when and otherwise but nothing is ever returned.
Cheers again!
Ah - yes - the node-set() function creates a document-node wrapper, so you need to do this instead, to select the node that was picked:
/Chriztian
- Oh, and to debug you can always just dump the contents of $sliderNode to a textarea:
/Chriztian
That's brilliant Chriztian!
All working now. Thanks for the help and the tips!
is working on a reply...