Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to add comments to an xml file using xslt or xpath

Tags:

xml

xslt

xpath

I have just learned xpath and xsl and i have a question.

How can i add e.g. the comment <!-- foo --> to the beginning of each xml element named foo?

Can i do it using xpath or xslt?

like image 849
Diemauerdk Avatar asked Oct 29 '25 21:10

Diemauerdk


1 Answers

Yes, there is an XSLT element for that: <xsl:comment>.

For doing what you describe, you can use the following:

<!-- Match foo elements in the XML -->
<xsl:template match="foo">
    <xsl:comment>foo</xsl:comment>
    <foo>
        <xsl:apply-templates />
    </foo>
</xsl:template>
like image 93
Pablo Pozo Avatar answered Nov 02 '25 11:11

Pablo Pozo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!