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.