This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Debugging.... Conditionally including XML
- To: "Mirick, John" <jmirick at doghouse dot com>
- Subject: Re: Debugging.... Conditionally including XML
- From: Jeni Tennison <mail at jenitennison dot com>
- Date: Mon, 13 Nov 2000 09:45:42 +0000
- CC: xsl-list at mulberrytech dot com
- Organization: Jeni Tennison Consulting Ltd
- References: <C75B7328A2FDD211AD3000805F9F0865027CE3E2@pant35.fcg.com>
- Reply-To: xsl-list at mulberrytech dot com
John,
> I would like to be able to do something like this in my XML file...
> <page>
> <content>....</content>
> if (debug = true)
> Include a debug data file, which would contain the data and
> item tags
> else
> The data and item tags will be returned to me.
> </page>
Probably the best way to approach this is to have a parameter called
debugp that is by default 'false' and can be set to true when you call
the processor from the command line.
To set up the parameter:
<xsl:param name="debugp" select="'false'" />
How you pass the value for the parameter into the stylesheet is
dependent on the processor that you're using. With Saxon, for
example, you'd use something like:
saxon -a -o out.xml in.xml debugp=true
Within the stylesheet, I would then set up a variable that is true()
when $debugp is 'true' and false() when $debugp is 'false' - this is
just to make testing for whether you're in debug mode easier:
<xsl:variable name="debug" select="$debugp = 'true'" />
You can then conditionally add text when in debug mode using xsl:if or
xsl:choose/xsl:when that test on the value of $debug:
<xsl:if test="$debug">
<!-- add some debugging text -->
</xsl:if>
<xsl:choose>
<xsl:when test="$debug">
<!-- text added when debugging -->
</xsl:when>
<xsl:otherwise>
<!-- text added when not debugging -->
</xsl:otherwise>
</xsl:choose>
To send the debugging information to the screen rather than into the
output file, you can use xsl:message within the debugging sections (or
outside them for messages that you always want to see).
I hope that helps,
Jeni
---
Jeni Tennison
http://www.jenitennison.com/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list