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



I have this xslt :

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
<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"/>

and this method:

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

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

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?

Dan Bass

First, there maybe a leak in your code, which is not your fault, but a
problem with Microsoft...;EN-US;Q316775&

What you should rather do is this:

static XmlTransform xslt = null;

public XmlDocument XslText ( string para )
if ( xslt == null )
xslt = new XslTransform();

// 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.
<watch line wraps>

Good luck.


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