xpblueScreenOfDeath
Programmer
- Sep 1, 2004
- 87
I have an xml and xslt document. What I want to do is use the xslt document to transform the xml into another format so I can read it into a dataset. When I use XslCompliedTransform to transform the document it adds a date to the transform document so that it throws an exception that the root element is missing.
code:
after transform:
xslt:
code:
Code:
XPathDocument xpathDoc = new XPathDocument("xdoc.xml");
XslCompiledTransform transform = new XslCompiledTransform();
XsltArgumentList args = new XsltArgumentList();
System.IO.FileStream file = new System.IO.FileStream("queryGroup.xml", System.IO.FileMode.Create);
DataSet ds = new DataSet();
System.IO.MemoryStream memStream = new System.IO.MemoryStream();
byte[] content;
XmlReader reader = XmlReader.Create(memStream);
args.AddParam("queryType", "", comboBox1.SelectedValue);
transform.Load("xtrans.xslt");
transform.Transform(xpathDoc, args, memStream);
content = memStream.ToArray();
file.Write(content, 0, content.Length);
file.Close();
ds.ReadXml(memStream);
after transform:
Code:
<?xml version="1.0" encoding="UTF-8" ?>
2006-09-19 17:29:33.917
<items>
<item>
<code>298</code>
<description>Name Index</description>
</item>
</items>
xslt:
Code:
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform">[/URL]
<xsl:param name="queryType" select="'History'"/>
<xsl:template match="/records/formats">
<items>
<item>
<code></code>
<description></description>
</item>
<xsl:for-each select="format[type = ($queryType) and not(query_id = (preceding-sibling::format)/query_id)]">
<item>
<code>
<xsl:value-of select="query_id"/>
</code>
<description>
<xsl:value-of select="query_desc"/>
</description>
</item>
</xsl:for-each>
</items>
</xsl:template>
</xsl:stylesheet>