C
cameron
I am attempting to pass in an XmlDocument as a parameter to a transform:
from my sample ASPX page:
string BaseDir = "/cameron/Play/ComplexParam/";
XmlDocument XSL = new XmlDocument();
XSL.Load(HttpContext.Current.Server.MapPath(BaseDir + "xsl.xsl"));
XmlDocument Data = new XmlDocument();
Data.Load( HttpContext.Current.Server.MapPath(BaseDir + "Data.xml") );
XmlDocument Betty = new XmlDocument();
Betty.LoadXml("<betty>Betty text<whooo>" +
"Woo text</whooo><weee/></betty>");
StringWriter Results = new StringWriter();
XslTransform XSLT = new XslTransform();
XSLT.Load(XSL.DocumentElement.CreateNavigator(),
new XmlUrlResolver(),
Assembly.GetCallingAssembly().Evidence);
XsltArgumentList Args = new XsltArgumentList();
Args.AddParam("InXML", "", Betty.DocumentElement);
//Args.AddParam("InXML", "", Betty);
//Args.AddParam("InXML", "", (XmlNode)Betty.DocumentElement);
XSLT.Transform(Data.DocumentElement.CreateNavigator(),
Args, Results, (XmlResolver)null);
HttpContext.Current.Response.Write("Transform = " +
Results.ToString());
---------------------------------------------
Data.xml:
<?xml version="1.0" encoding="utf-8" ?>
<Data>
<SomeData>Data-here</SomeData>
</Data>
---------------------------------------------
xsl.xsl
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:user="http://mycompany.com/mynamespace"
exclude-result-prefixes="msxsl user"
version="1.0">
<xsl
utput method="xml" omit-xml-declaration="yes"/>
<xsl
aram name="InXML"/>
<xsl:template match="/">
got root
<xsl:if test="$InXML">
<p>InXml looks good to me!</p>
<p>whoo count <xsl:value-of select="count($InXML/whooo)"/></p>
<p>weee count <xsl:value-of select="count($InXML/weee)"/></p>
<p>text '<xsl:value-of select="$InXML/text()"/>'</p>
<xsl:for-each select="$InXML/whooo">
<p>have child</p>
</xsl:for-each>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
---------------------------------------------
Output:
got root
InXml looks good to me!
whoo count 0
weee count 0
text ''
---------------------------------------------
I can do this in IE as a client-side transform without issue but not in
C#. Can anyone see what I am doing wrong?
Thanks
-Cam
from my sample ASPX page:
string BaseDir = "/cameron/Play/ComplexParam/";
XmlDocument XSL = new XmlDocument();
XSL.Load(HttpContext.Current.Server.MapPath(BaseDir + "xsl.xsl"));
XmlDocument Data = new XmlDocument();
Data.Load( HttpContext.Current.Server.MapPath(BaseDir + "Data.xml") );
XmlDocument Betty = new XmlDocument();
Betty.LoadXml("<betty>Betty text<whooo>" +
"Woo text</whooo><weee/></betty>");
StringWriter Results = new StringWriter();
XslTransform XSLT = new XslTransform();
XSLT.Load(XSL.DocumentElement.CreateNavigator(),
new XmlUrlResolver(),
Assembly.GetCallingAssembly().Evidence);
XsltArgumentList Args = new XsltArgumentList();
Args.AddParam("InXML", "", Betty.DocumentElement);
//Args.AddParam("InXML", "", Betty);
//Args.AddParam("InXML", "", (XmlNode)Betty.DocumentElement);
XSLT.Transform(Data.DocumentElement.CreateNavigator(),
Args, Results, (XmlResolver)null);
HttpContext.Current.Response.Write("Transform = " +
Results.ToString());
---------------------------------------------
Data.xml:
<?xml version="1.0" encoding="utf-8" ?>
<Data>
<SomeData>Data-here</SomeData>
</Data>
---------------------------------------------
xsl.xsl
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:user="http://mycompany.com/mynamespace"
exclude-result-prefixes="msxsl user"
version="1.0">
<xsl

<xsl

<xsl:template match="/">
got root
<xsl:if test="$InXML">
<p>InXml looks good to me!</p>
<p>whoo count <xsl:value-of select="count($InXML/whooo)"/></p>
<p>weee count <xsl:value-of select="count($InXML/weee)"/></p>
<p>text '<xsl:value-of select="$InXML/text()"/>'</p>
<xsl:for-each select="$InXML/whooo">
<p>have child</p>
</xsl:for-each>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
---------------------------------------------
Output:
got root
InXml looks good to me!
whoo count 0
weee count 0
text ''
---------------------------------------------
I can do this in IE as a client-side transform without issue but not in
C#. Can anyone see what I am doing wrong?
Thanks
-Cam