I'm making a survey tool. Each respondent will be asked to answer questions on (for example) cakes. The number and types of cake will be different for each respondent. The format of the survey will be saved in a file called survey.xml. So the survey may be like the following:

Rates these cakes fool.
Birthday 0 1 2
Christmas 0 1 2
Lovely 0 1 2

Anyway, I want to pass these cakes into XSLT as a temporary XML document. E.g.:

<cakes>
  <cake>Birthday</cake>
  <cake>Christmas</cake>
  <cake>Lovely</cake>
</cakes>

I save that in a string and throw it in an XDocument like so:

dim cakesXmlDoc as XDocument
cakesXmlDoc = XDocument.Parse(xmlString)

Now I simply want to pass that to XSLT as a parameter and create a table with a new row for each cake. I have the following:

Transformer.xlst:

<?xml version="1.0" encoding="iso-8859-1"?>
 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
 
  <xsl:param name="cakes_doc" />
  <xsl:template match="/">
    <html>
      <body>
        <xsl:for-each select="msxsl:node-set($cakes_doc)/cakes/cake">
          <p><xsl:value-of select="current()" /></p>
       </xsl:for-each>
      </body>
    </html>
  </xsl:template>
 
</xsl:stylesheet>

Where I pass the cakes_doc like this:

Dim xslArgs As New Xsl.XsltArgumentList
xslArgs.AddParam("cakes_doc", "", cakesXmlDoc)
xmlContent.TransformArgumentList = xslArgs
xmlContent.DocumentSource = "survey.xml"

Note: xmlContent is an XML web control:

<asp:Xml ID="xmlContent" runat="server" TransformSource="~/XSLT/Transformer.xslt"></asp:Xml>

But I get the error "Cannot convert the operand to 'Result tree fragment'." Can anyone tell me what's wrong? Or maybe a completely alternative method? Thanks.

In the event someone ever comes across this problem:

I eventually sorted it by using XslCompiledTransform rather than XslTransform which is apparently now obselete.

XslCompiledTransform doesn't seem to be compatible with the xml web control so I got rid of it and just output my transformation to a div using StringWriter.

Probably not the way to do it but it works.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.