It's gotta be something real obvious: Transform with param

G

Guest

I have this xslt :

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="p" select="'q'"/>
<xsl:blush:utput method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

<xsl:template match="/">
<xsl:element name="test">
<xsl:value-of select="$p"/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>

and this method:

[WebMethod]
public XmlDocument Xsltest (String para)
{
XmlDocument tmp_xdoc = new XmlDocument();
XmlReader xmlrdr;
XsltArgumentList xslArg = new XsltArgumentList();
XslTransform xslt = new XslTransform();

try{
xslArg.AddParam("p", "", para);
xslt.Load(Server.MapPath("DescribeTypeTransform2.xslt"));
//data_xdoc exists already as global scope XmlDocument
xmlrdr = xslt.Transform(data_xdoc, xslArg);
tmp_xdoc.Load(xmlrdr);
}
catch (Exception e){
String s = "<error>" + e.Message + "</error>";
tmp_xdoc.LoadXml(s);
}

return tmp_xdoc;

}//end DocumentFeatureType

What I expected to see was

<?xml version="1.0" encoding="utf-8" ?>
<test>[the value of para as passed to the method or 'q']</test>

Instead I get

<?xml version="1.0" encoding="utf-8" ?>
<test />

But it works as expected in XMLSpy. What gives?
 
D

Dan Bass

First, there maybe a leak in your code, which is not your fault, but a
problem with Microsoft...
http://support.microsoft.com/default.aspx?scid=KB;EN-US;Q316775&

What you should rather do is this:

//---------------------------------------------
static XmlTransform xslt = null;

[WebMethod]
public XmlDocument XslText ( string para )
{
if ( xslt == null )
{
xslt = new XslTransform();
xslt.Load(Server.MapPath("DescribeTypeTransform2.xslt"));
}

// etc... here
}
//---------------------------------------------


Second, don't expect XslTransform to work the same as every other MsXsl
Transform, because you'll be disappointed. I've had the same problems with
Xsl in the past... looking at your code, the only thing that it may be that
i can think of is the default value select="'q'" in your param
declaration that it "MAY" be struggling with... Otherwise i've tested it and
it looks good.

there's an example on the MSDN that you may want to look at which follows
your syntax.

http://msdn.microsoft.com/library/d...mxmlxslxsltargumentlistclassaddparamtopic.asp
<watch line wraps>

Good luck.

Daniel.
 

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