Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Using <a href="http://saxon.sourceforge.net/" rel="nofollow">Saxon-B 9.1.0.8</a>, you can have a pretty clean solution:</p> <h2>source.xml</h2> <pre><code>&lt;root&gt; &lt;KeepMeTag someAttribute="something"&gt; &lt;SomeOtherTag someAttribute="something" /&gt; &lt;/KeepMeTag&gt; &lt;/root&gt; </code></pre> <h2>build.xml</h2> <pre><code>&lt;project name="ant-xslt-comment-out-element" default="run" basedir="."&gt; &lt;target name="run"&gt; &lt;fail unless="out.dir"/&gt; &lt;xslt style="transform.xsl" includes="source.xml" destdir="${out.dir}" &gt; &lt;factory name="net.sf.saxon.TransformerFactoryImpl"/&gt; &lt;identitymapper/&gt; &lt;/xslt&gt; &lt;/target&gt; &lt;/project&gt; </code></pre> <h2>transform.xsl</h2> <pre><code>&lt;?xml version="1.0"?&gt; &lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:saxon="http://saxon.sf.net/" &gt; &lt;xsl:output method="xml" indent="yes" /&gt; &lt;!-- To serialize with saxon:serialize() --&gt; &lt;xsl:output name="default" indent="yes" omit-xml-declaration="yes"/&gt; &lt;!-- XSLT identity transformation --&gt; &lt;xsl:template match="@*|node()" name="identity"&gt; &lt;xsl:copy&gt; &lt;xsl:apply-templates select="@*|node()"/&gt; &lt;/xsl:copy&gt; &lt;/xsl:template&gt; &lt;xsl:template match="SomeOtherTag"&gt; &lt;xsl:comment&gt; &lt;xsl:value-of select="saxon:serialize(., 'default')" /&gt; &lt;/xsl:comment&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <h2>Ant command</h2> <pre><code>ant -lib saxon9.jar </code></pre> <h2>Resulting XML</h2> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;root&gt; &lt;KeepMeTag someAttribute="something"&gt; &lt;!--&lt;SomeOtherTag someAttribute="something"/&gt;--&gt; &lt;/KeepMeTag&gt; &lt;/root&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload