XSLT transforms and complex parameter types

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:blush:utput method="xml" omit-xml-declaration="yes"/>

<xsl:param 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
 
K

Kevin Yu [MSFT]

Hi Cameron,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that XSLTransform works incorrectly when the
parameter contains node. If there is any misunderstanding, please feel free
to let me know.

Based on my research, this is a known issue in current .net framework.
Since IE uses MSXML to process xml data, it is working properly. This issue
will be fixed in the next version of .net framework. Currently, I think you
have to use MSXML to process with the xsl.

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top