views:

27

answers:

1

I'm debugging a transform with Visual Studio. The application that uses the transform normally also passes in some parameters:

XslTransform xslTransform = new XslTransform();
xslTransform.Load(myXslt);
XsltArgumentList transformArgumentList = new XsltArgumentList();
transformArgumentList.AddParam(paramName1, String.Empty, paramValue1); // this
transformArgumentList.AddParam(paramName2, String.Empty, paramValue2); // and this
xslTransform.Transform(inputStream, transformArgumentList, outputStream);

How can I set the parameters when debugging?

+2  A: 

How can I set the parameters when debugging?

You should use the following XslCompiledTransform constructor:

public XslCompiledTransform(
    bool enableDebug
)

with the enableDebug argument set to true.

Then you can start debugging and the debugger will stop on breakpoints set in your XSLT transformation.

Here is an example:

// Enable XSLT debugging.
XslCompiledTransform xslt = new XslCompiledTransform(true);

// Load the style sheet.
xslt.Load("MyTransformation.xsl");

// Create the writer.
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent=true;
XmlWriter writer = XmlWriter.Create("output.xml", settings);

// Execute the transformation.
xslt.Transform("books.xml", writer);
writer.Close();

Of course, if you are lazy, you may just hardcode the values of the parameters in your XSLT stylesheet:

<xsl:param name="param1" select="SomeValue1"/>
<xsl:param name="param2" select="SomeValue2"/>
Dimitre Novatchev
Is this the only way to do this? I'd rather not have to run the entire app each time, as there is quite a lot of work done before the transform.
fatcat1111
@fatcat1111: if you don't want to hardcode the `<xsl:param>` s in your XSLT code, then this is the only way to debug and pass parameters. Otherwise, you may hardcode the params: `<xsl:param name="pMyParam" select="MyValue"/>'
Dimitre Novatchev
Thank you very much!
fatcat1111