I have several XSLT code files and I want to modify them to add some comments after functions or explaining them etc. So let's imagine I have 10 XSLT files and I want to transform them with additional comments for each function. The code will not change at all, I just want to add automatic documentation – that's all.
Absolutely. Meta XSLT transformations are wonderfully powerful.
Just adding comments is a relatively simple matter that can be performed with the identity transformation plus some specialized templates that insert comments before, after, or around a site of your choosing.
For example:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!-- identity transformation -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<!-- override for inserting a comment -->
<xsl:template match="div[@id='target']">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
<xsl:comment>The above div element is comment-worthy.</xsl:comment>
</xsl:template>
</xsl:stylesheet>
More complicated meta XSLT transformations are certainly possible too:
XSLT is XML so you can use it as the input and you can as well produce it as the output of an XSLT transformation. Creating new XSLT elements as a result might require the use of https://www.w3.org/TR/xslt-30/#element-namespace-alias but inserting comments can be done with xsl:comment
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.