How to create XSL nodeset from string

467 views Asked by At

I can not create a XSL nodeset from a string. I can create a nodeset from a Result Tree Fragment. This stylesheet shows both attempts.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:exsl="http://exslt.org/common"
version="1.0">

  <xsl:output method="xml" indent="yes" />

  <xsl:variable name="rtf">
      <root>
          <child>
          </child>
      </root>
  </xsl:variable>

  <xsl:variable name="rtfNs" select="exsl:node-set($rtf)" />

  <xsl:variable name="str" select="'&lt;root&gt;&lt;child&gt;&lt;/child&gt;&lt;/root&gt;'" />

  <xsl:variable name="strNs" select="exsl:node-set($str)" />

  <xsl:template match="/">
    <xsl:copy-of select="$rtfNs" />
    <xsl:copy-of select="$rtfNs/root/child" />
    <xsl:copy-of select="$strNs" />
  </xsl:template>

</xsl:stylesheet>

Produces

<?xml version="1.0" encoding="UTF-8"?>
<root xmlns:exsl="http://exslt.org/common">
   <child/>
</root>
<child xmlns:exsl="http://exslt.org/common"/>&lt;root&gt;&lt;child&gt;&lt;/child&gt;&lt;/root&gt;

The code shows a nodeset can be created from an RTF and used in a select attribute. The attempt to create a nodeset from a string results in a string with embedded entities (i.e. &lt; and &gt;). The string can not be defined without using the entities. This question is a simplification of an attempt to pass a external string into the stylesheet from .NET System.Xml.Xsl and convert that string into a nodeset.

1

There are 1 answers

0
DSHCS On

I did get a solution on the .NET side, but want to get the XSL side responses too...

Dim objXmlDoc As System.Xml.XmlDocument = New System.Xml.XmlDocument()
objXmlDoc.LoadXml("<root><child></child></root>")
Dim objXmlNav As System.Xml.XPath.XPathNavigator = objXmlDoc.CreateNavigator()
objXmlNav.MoveToRoot()

Dim objValidationArgList As New System.Xml.Xsl.XsltArgumentList
objValidationArgList.AddParam("test", "", objXmlNav)

This passed an RTF into the stylesheet and when processed with node-set($test) resulted in a nodeset that could be used just like one created from an internal (xsl:variable) RTF.