[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

[xsl] commenting in xslt2.0 - input-subtree to ouput-comment


Subject: [xsl] commenting in xslt2.0 - input-subtree to ouput-comment
From: Siegfried Baiz <baiz@xxxxxxxxx>
Date: Mon, 23 May 2005 13:14:07 +0200

Hi,

is it possible to create an xml comment in the XSLT-output
which consists of a complete subtree of the xml-input-document?
Im using XSLT 2.0.

I've been trying things like:
   <xsl:comment>
       <xsl:copy-of select="//section[3]"/>
   <xsl:comment>
but but never got the desired output like:
   <!--
       <section>... please comment the section in ...<section/>
   -->

Siggi



Bryan Rasmussen wrote:

Hi,
I just had an idea about how to write useful comments in XSLT (which I very
seldomly see), it struck me that what one needs to see in a complex transform is
a comment that explains the expected input and the expected output, the reason
being that the input is in a format that the developer working with the xslt
might not know, or even if they have developed the stylesheet themselves might
not remember the expected input, so:

<xsl:template match="x:*[starts-with(@type,'payment')][1]">

<!--
if input = <x:restrictive type="paymentdue" amount="$500"/>
the output will be <div class="paymentdue" onclick="calculator(paymentdue,500)">
paymentdue for $500
</div>


the various types of class expected are paymentdue, paymentmade, paymentpast



-->
<div class="{@type}"
onclick="calculator({concat(@type,',',substring(@amount,2,string-length(@amount)-1))})">
<xsl:value-of select="concat(@type,' for ',@amount)"/>
</div>
</xsl:template>

yes I know this is not a particular good way to structure ones output, it's a
spur of the moment example. Obviously the comment could be done as an xml
fragment, so
<!--
<doc:fragment>
<doc:input>
<x:restrictive type="paymentdue" amount="$500"/>
</doc:input>
<doc:output>
<div class="paymentdue" onclick="calculator(paymentdue,500)">
paymentdue for $500
</div>

</doc:output>
<doc:remarks>
the various types of class expected are paymentdue, paymentmade, paymentpast
</doc:remarks>
</doc:fragment>
-->

I haven't defined any namespaces for the examples.


Current Thread
Keywords