Reputation: 36
The code below works for all examples I've tried in a Windows 10 Universal app. But in a Windows 8.1 app it does not output any static html content from the xsl template except the xml document declaration and the inner xml.
Any ideas on why it behaves like this in WinRT?
private static string TransformToString(string xml, string xsl)
{
var xmlDocument = new XmlDocument();
xmlDocument.LoadXml(xml);
var xslDocument = new XmlDocument();
xslDocument.LoadXml(xsl);
var processor = new XsltProcessor(xslDocument);
//string transformation = processor.TransformToString(xmlDocument.LastChild);
string transformation = processor.TransformToString(xmlDocument);
return transformation;
}
The example xml:
<library xmlns='http://www.microsoft.com'>
<book>
<chapter></chapter>
<chapter>
<section>
<paragraph a="b">1</paragraph>
<paragraph a="b">2</paragraph>
</section>
</chapter>
</book>
</library>
Example xsl:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:m="http://www.microsoft.com">
<xsl:template match="/">
<html><body><table>
<tr>
<td>Attribute</td>
<td>Value</td>
</tr>
<xsl:for-each select="m:library/m:book/m:chapter/m:section/m:paragraph">
<tr>
<td><xsl:value-of select="@a"/></td>
<td><xsl:value-of select="."/></td>
</tr>
</xsl:for-each>
</table></body></html>
</xsl:template>
Result
<?xml version="1.0" encoding="utf-8"?>12
Upvotes: 1
Views: 115
Reputation: 36
The problem was calling TransformToString
with xmlDocument.LastChild
instead of xmlDocument
.
Upvotes: 1