XSLT2.0 output XML node tree in comment tags

R

RolfK

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
 
M

Martin Honnen

RolfK said:
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>
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top