11

I'm currently working on a project that involves a lot of XSLT transformations and I really need a debugger (I have XSLTs that are 1000+ lines long and I didn't write them :-).

The project is written in C# and makes use of extension objects:

xslArg.AddExtensionObject("urn:<obj>", new <Obj>());

From my knowledge, in this situation Visual Studio is the only tool that can help me debug the transformations step-by-step. The static debugger is no use because of the extension objects (it throws an error when it reaches elements that reference their namespace). Fortunately, I've found this thread which gave me a starting point (at least I know it can be done).

After searching MSDN, I found the criteria that makes stepping into the transform possible. They are listed here. In short:

  • the XML and the XSLT must be loaded via a class that has the IXmlLineInfo interface (XmlReader & co.)
  • the XML resolver used in the XSLTCompiledTransform constructor is file-based (XmlUriResolver should work).
  • the stylesheet should be on the local machine or on the intranet (?)

From what I can tell, I fit all these criteria, but it still doesn't work. The relevant code samples are posted below:

// [...]

xslTransform = new XslCompiledTransform(true);

xslTransform.Load(XmlReader.Create(new StringReader(contents)), null, new BaseUriXmlResolver(xslLocalPath));

// [...]

// I already had the xml loaded in an xmlDocument 
// so I have to convert to an XmlReader
XmlTextReader r = new XmlTextReader(new StringReader(xmlDoc.OuterXml));

XsltArgumentList xslArg = new XsltArgumentList();
xslArg.AddExtensionObject("urn:[...]", new [...]());
xslTransform.Transform(r, xslArg, context.Response.Output);

I really don't get what I'm doing wrong. I've checked the interfaces on both XmlReader objects and they implement the required one. Also, BaseUriXmlResolver inherits from XmlUriResolver and the stylesheet is stored locally. The screenshot below is what I get when stepping into the Transform function. First I can see the stylesheet code after stepping through the parameters (on template-match), I get this:

The error I get when I step into the stylesheet

If anyone has any idea why it doesn't work or has an alternative way of getting it to work I'd be much obliged :).

Thanks,
Alex

4

2 に答える 2

2

拡張オブジェクトの使用法についてはわかりませんが、VS2010 のコードでの XSLT 変換のデバッグに問題があることは理解しています。XSLT 変換のデバッグに使用する関数は次のとおりです。

 public string ApplyTransformation(string inputFilePath, string xsltFileContent)
    {
        XslCompiledTransform transform = new XslCompiledTransform(debugEnabled);

        File.WriteAllText(xsltTempFilePath,xsltFileContent);
        transform.Load(xsltTempFilePath, XsltSettings.TrustedXslt, new XmlUrlResolver());

        XmlReader reader = XmlReader.Create(inputFilePath);
        StringWriter output = new StringWriter();
        XmlWriter writer =  XmlWriter.Create(output,transform.OutputSettings);
        transform.Transform(reader,writer);
        return output.ToString();
    }

残念ながら、VS2010 XSLT デバッガーにはバグがあり、VS2008 よりもデバッグ エクスペリエンスが低下します。

于 2010-05-25T14:55:14.530 に答える
0

XMLSpyXSLTデバッガーを使用したデバッグを検討してください。それはいつも私のために働きます。

于 2010-06-28T20:07:57.217 に答える