简体   繁体   English

是否可以将XSLT代码转换为另一个XSLT代码(元XSLT)?

[英]Is it possible to transform XSLT code with another XSLT code (meta XSLT)?

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. 我有几个XSLT代码文件,我想对其进行修改以在函数后添加一些注释或对其进行解释等。因此,让我们想象一下,我有10个XSLT文件,并且希望为每个函数添加附加注释来对其进行转换。 The code will not change at all, I just want to add automatic documentation – that's all. 代码完全不会改变,我只想添加自动文档即可。

Absolutely. 绝对。 Meta XSLT transformations are wonderfully powerful. Meta XSLT转换功能强大。

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: 当然也可以进行更复杂的meta XSLT转换:

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. XSLT是XML,因此您可以将其用作输入,也可以将其生成为XSLT转换的输出。 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 . 因此,创建新的XSLT元素可能需要使用https://www.w3.org/TR/xslt-30/#element-namespace-alias,但是插入注释可以使用xsl:comment

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM