XSLT2.0 output XML node tree in comment tags

Discussion in 'XML' started by RolfK, Jan 12, 2008.

  1. RolfK

    RolfK Guest

    Hello All,

    I'm trying to output an XML node tree in COMMENT tags.
    Processing is done with XSLT2.0.

    The output schould be avild xml like this:

    <root>
    <e c="some element 1"/>
    <e c="some element 2"/>
    <!--
    <e c="some element 2 in comment"/>
    -->

    <e c="some element 2"/>
    </root>

    So my questions is how to get the '<e>some element 2 in comment</e>'
    in the comment tags
    I tried this
    <xsl:comment>
    <xsl:copy-of select="...somenode...."/>
    </xsl:comment>

    But this does not create any printed xml as we know.
    What is the solution ?

    Rolf
    RolfK, Jan 12, 2008
    #1
    1. Advertising

  2. RolfK wrote:

    > I'm trying to output an XML node tree in COMMENT tags.


    Comments in XML do not contain other nodes.

    > Processing is done with XSLT2.0.
    >
    > The output schould be avild xml like this:
    >
    > <root>
    > <e c="some element 1"/>
    > <e c="some element 2"/>
    > <!--
    > <e c="some element 2 in comment"/>
    > -->
    >
    > <e c="some element 2"/>
    > </root>
    >
    > So my questions is how to get the '<e>some element 2 in comment</e>'
    > in the comment tags
    > I tried this
    > <xsl:comment>
    > <xsl:copy-of select="...somenode...."/>
    > </xsl:comment>
    >
    > But this does not create any printed xml as we know.
    > What is the solution ?


    You would have to serialize the node and put the serialized string into
    the comment. Saxon 9 has an extension function to serialize, see
    <URL:http://www.saxonica.com/documentation/extensions/functions/serialize.html>

    Example:

    <xsl:stylesheet
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:saxon="http://saxon.sf.net/"
    exclude-result-prefixes="saxon"
    version="2.0">

    <xsl:eek:utput method="xml" name="o1"/>

    <xsl:template match="/">
    <xsl:comment select="saxon:serialize(*, 'o1')"/>
    <example/>
    </xsl:template>

    </xsl:stylesheet>


    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Jan 12, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    1,413
  2. Alec S.
    Replies:
    10
    Views:
    10,091
    Alec S.
    Apr 16, 2005
  3. Tjerk Wolterink
    Replies:
    2
    Views:
    1,404
    Dimitre Novatchev
    Aug 24, 2006
  4. Peter Mueller
    Replies:
    6
    Views:
    4,532
    Stefan Ram
    Jan 13, 2008
  5. John Bankhead

    Null parent node on custom tree node after populate on demand

    John Bankhead, Dec 4, 2006, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    271
    John Bankhead
    Dec 4, 2006
Loading...

Share This Page