How to “debug” XSLTs

I don’t use any specific tool to test and debug XSLT files. In 90%+ cases the problem is with the XPath and I need to find the exact place where it becomes wrong. So, I use the “count()” function and (sometimes) xsl:comment, like this:

<xsl:comment>
	-<xsl:value-of select="count(aaa)"/>
	-<xsl:value-of select="count(aaa/bbb)"/>
	-<xsl:value-of select="count(aaa/bbb/ccc)"/>
	-<xsl:value-of select="count(aaa/bbb/ccc[@ddd = 'eee'])"/>
</xsl:comment>

If I see something like

<!--
  -1
  -1
  -3
  -0
-->

in the output, it’s clear that the problem with the XPath condition in the brackets.

Gennady Kim

Advertisements

One thought on “How to “debug” XSLTs

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s