I want to create a html list () from an xml using xslt. I was able to do so with an xml file and a xslt file. Now I want to do it with an xml string or XmlDocument and and xslt file.
This is my current code:
private String toHTML(XmlDocument xmlDocument)
{
System.IO.StringWriter sw = new System.IO.StringWriter();
XslCompiledTransform xslTrans = new XslCompiledTransform();
xslTrans.Load(Server.MapPath("Xslt/Permisos.xslt"));
xslTrans.Transform(xmlDocument.CreateNavigator(), new XsltArgumentList(), sw);
return sw.ToString();
}
It is on a single web application assembly. No exception is thrown. Just returns "".
My XSLT
<?xml version="1.0" encoding="utf-8"?>
<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:output method="html" indent="yes"/>
<xsl:template match="/">
<xsl:for-each select="menus">
<ul>
<xsl:for-each select="menu">
<li>
<a href="{url}">
<xsl:value-of select="nombre" />
</a>
<ul>
<xsl:for-each select="submenu">
<li>
<a href="{url}">
<xsl:value-of select="nombre" />
</a>
</li>
</xsl:for-each>
</ul>
</li>
</xsl:for-each>
</ul>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
MY XML
<?xml version="1.0" encoding="UTF-8"?><menus xmlns="http://www.xxxxx.com"><menu><nombre>Main</nombre><url>#</url><submenu><nombre>Sub</nombre><url>#</url></submenu><submenu><nombre>Sub</nombre><url>#</url></submenu><submenu><nombre>Sub</nombre><url>#</url></submenu><submenu><nombre>Sub</nombre><url>#</url></submenu><submenu><nombre>Sub</nombre><url>#</url></submenu><submenu><nombre>Sub</nombre><url>#</url></submenu><submenu><nombre>Sub</nombre><url>#</url></submenu><submenu><nombre>Sub</nombre><url>#</url></submenu><submenu><nombre>Sub</nombre><url>#</url></submenu><submenu><nombre>Sub</nombre><url>#</url></submenu></menu></menus>
Thanks!