xsl-list
[Top] [All Lists]

inserting HTML comments

2004-11-02 08:30:43
Hi All,

I seem to have a problem with inserting HTML comments in the HTML output
of an
XSL transformation.

The problem description is as follows:
1. I have an XML file from which I generate the HTML output.
(source.xml)
2. In the XSL file I have a template which contains something like this:

<PRE>
  <B>
    <xsl:text>some text node </xsl:text>
  </B>
  <xsl:call-template name="insert-anchor">
    <xsl:with-param name="anchor" select="someNode"/>
  </xsl:call-template>
</PRE>

3. and the insert-anchor template looks something like:

<xsl:template name="insert-anchor">
  <xsl:comment> This is a comment </xsl:comment>
  <A>
    <xsl:attribute name="HREF">
      <xsl:value-of select="concat (string (someNode), '.html')"/>
    </xsl:attribute>
    <xsl:value-of select="string (someNode)"/>
  </A>
</xsl:template>

4. I'd expect the output to look like this:

<PRE><B>some text node </B><!-- This is a comment --><A
HREF="value-of-someNode.html">value-of-someNode</A></PRE>

5. but instead I get this:

<PRE>
<B>some text node </B>
<!-- This is a comment -->
<A HREF="value-of-someNode.html">value-of-someNode</A>
</PRE>

6. However, if I don't insert the <B> tags around the text node, I get
this:

<PRE>some text node <!-- This is a comment --><A
HREF="value-of-someNode.html">value-of-someNode</A></PRE>

What I need is the comment placed _right before_ the anchor tag without
any
kind of whitespace inbetween (and of course no whitespace inserted into
a <PRE>
tag at all).


Some more background info:
1. I'm using Xalan-C 1.8 with Xerces-C 2.5.0 (Windows).
2. I do have the xsl:output element set to html and indent="yes", but
even if I
turn off the indentation, the problem persists.
3. Of course my original templates are somewhat more comlicated than
these, but
I think the whole problem boils down to the mentioned parts. If you
think it
may help I can post a more detailed template.


Questions:
1. Is this behaviour XSL inherent or XSL processor dependant?
2. If it is the former, then how could I achieve what I'm trying to do?

TIA:
        Andras Babos.


<Prev in Thread] Current Thread [Next in Thread>