2

I have following XSLT code:

<xsl:stylesheet
  version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:exslt="http://exslt.org/common"
  xmlns:msxml="urn:schemas-microsoft-com:xslt" xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon"
  xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes"  xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath"
  xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings"
  xmlns:DesignetExtender ="urn:DesignetExtender"
  xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets"
  exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath 
  Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets DesignetExtender ">

....

<xsl:variable name="test">
<xsl:value-of select="exslt:node-set($HtmlPermulations)" disable-output-escaping="yes"/>
</xsl:variable>

Value for HtmlPermulations is as follow:

&lt;root&gt;&lt;item&gt;Stationcar
                                        &lt;/item&gt;&lt;item&gt;Cabriolet
                                        &lt;/item&gt;&lt;item&gt;SUV&lt;/item&gt;&lt;item&gt;Stationcar
                                         Cabriolet&lt;/item&gt;&lt;item&gt;Stationcar
                                         SUV&lt;/item&gt;&lt;item&gt;Cabriolet
                                         SUV&lt;/item&gt;&lt;item&gt;Stationcar
                                         Cabriolet
                                         SUV&lt;/item&gt;&lt;/root&gt;

But when I am trying to use it in this for-each loop:

<xsl:for-each select="$test/root/item">
 <xsl:value-of select="."/>
</xsl:for-each>

I am getting this error message:

To use a result tree fragment in a path expression, first convert it to a node-set using the msxsl:node-set() function.

Can anyone help?

amir moradifard
  • 353
  • 1
  • 8
  • 26

1 Answers1

1

You seem to have a string with markup you want to parse into a tree of nodes. the msxsl:node-set function does not do that, it takes a result tree fragment and converts it into a node set. The disable-output-escaping does not help as it is only used in final serialization step but not inside of a variable. So with pure XSLT 1.0 all you could do is write two stylesheets, the first can use disable-output-escaping to output the contents of the variable, the second can the process that output. Or you need to check whether your XSLT processor supports an extension function or allows you to implement one that parses the string of markup into a tree of nodes.

Martin Honnen
  • 160,499
  • 6
  • 90
  • 110
  • Thanks for the response. Yes I came to this solution as well, but still wondering if there is any faster workarounds as well? – amir moradifard Mar 17 '14 at 11:11
  • I am not familiar with Umbraco, the use of `msxsl:node-set` suggests it uses Microsoft's MSXML or XslCompiledTransform. It seems http://myxsl.net/xslcompiledtransform/extensions/w3c.xpath.xsl#fn-parse-xml-fragment is an attempt to provide an extension for `XslCompiledTransform`. How/Whether you can use that with Umbraco I don't know. – Martin Honnen Mar 17 '14 at 11:21