[英]Is it possible to transform XSLT code with another XSLT code (meta XSLT)?
我有幾個XSLT代碼文件,我想對其進行修改以在函數后添加一些注釋或對其進行解釋等。因此,讓我們想象一下,我有10個XSLT文件,並且希望為每個函數添加附加注釋來對其進行轉換。 代碼完全不會改變,我只想添加自動文檔即可。
絕對。 Meta XSLT轉換功能強大。
僅添加評論是一個相對簡單的事情,可以通過身份轉換以及一些專門的模板來執行,這些模板可以在您選擇的站點之前,之后或周圍插入評論。
例如:
<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>
當然也可以進行更復雜的meta XSLT轉換:
XSLT是XML,因此您可以將其用作輸入,也可以將其生成為XSLT轉換的輸出。 因此,創建新的XSLT元素可能需要使用https://www.w3.org/TR/xslt-30/#element-namespace-alias,但是插入注釋可以使用xsl:comment
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.