RE: [xsl] working with xsl:comment

Subject: RE: [xsl] working with xsl:comment
From: "Andrew Welch" <ajwelch@xxxxxxxxxxxxxxx>
Date: Fri, 24 Jun 2005 12:42:49 +0100
> Sorry, another query in quick succession but like earlier I might be
> missing something rather obvious.
>
> I am writing some information within the <xsl:comment> tags.
> I want to
> later retreive this content in another .xsl file. How do I do
> it? Also
> can I retrieve the container node of this comment?
>
> E.g <TD width="50%"><FONT SIZE="4" COLOR="red">Checking for
> existence of
> 'Wood'...</FONT>
>                <!--Wood--></TD>
>
> So how do I get the information 'Wood' as well as the position of the
> containing <TD> so that I can proceed to find other sibling
> <TD>s from
> this point?

Use the comment() function eg:

<xsl:template match="comment()">
  <xsl:value-of select="."/>
</xsl:template>

Which will output 'Wood'.  If you want <!--Wood--> then use copy-of
instead of value-of.

To select the TD that contains a comment just use a predicate eg:

<xsl:apply-templates select="TD[comment()]"/>

cheers
andrew

Current Thread