Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to debug template rules?

Status
Not open for further replies.

gorgonz

Technical User
Jan 9, 2004
5
DE
since I'm not to familiar with xsl yet, I would like to do some kind of debugging. I want to understand it in a better way, which template rule created which kind of output. The hard coded way is something like this:

<xsl:template match=&quot;mybold&quot;>
{mybold}<b>
<xsl:apply-templates/>
</b>{/mybold}
</xsl:template>

It results in the additional debug braces {mybold} and {/mybold}

The disadvantage is, that I cannot switch it on or off. So I would prefer to have a global variable 'debug' with values on/off and a code snippet, that decides within any template, whether the debug braces are to be printed. Someone got an idea, how to do that - without being too complicated ;-) ?

thx again

 
Having the xml code:

Code:
<?xml version=&quot;1.0&quot; standalone=&quot;no&quot; ?>
<?xml-stylesheet href=&quot;bold.xsl&quot; type=&quot;text/xsl&quot; ?>

<container>
 this is <mybold>bold</mybold>
</container>

I tried this approach:

Code:
<xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot;[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform&quot;>[/URL]

 <!-- set global variable -->
 <xsl:param name=&quot;debug&quot;>on</xsl:param>

 <xsl:template match=&quot;/&quot;>
  <HTML> 
   <HEAD> 
    <TITLE>bold style</TITLE>
   </HEAD> 
   <BODY bgcolor=&quot;lightgreen&quot;> 
    <xsl:apply-templates/> 
   </BODY> 
  </HTML> 
 </xsl:template>

 <xsl:template match=&quot;mybold&quot;>

  <!-- test, if the global variable was set to 'on' -->
  <xsl:if test=&quot;$debug=on&quot;>
   <xsl:text>{</xsl:text>
   <xsl:value-of select=&quot;name()&quot; />
   <xsl:text>}</xsl:text>
  </xsl:if>
  <!-- end of debug tag -->

  <b>
  <xsl:apply-templates/>
  </b>

  <!-- test, if the global variable was set to 'on' -->
  <xsl:if test=&quot;$debug=on&quot;>
   <xsl:text>{/</xsl:text>
   <xsl:value-of select=&quot;name()&quot; />
   <xsl:text>}</xsl:text>
  </xsl:if>
  <!-- end of debug tag -->

 </xsl:template>

</xsl:stylesheet>

The bold rule works, but the 'if' condition is ignored. Is there an idea, why it will not work?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top