1 回答
TA贡献1773条经验 获得超3个赞
转换设计应该是从标识转换开始(请参阅 https://www.w3.org/TR/xslt20/#element-copy 中的“示例:标识转换”部分),然后只为要转换的节点添加模板,在 XSLT 3 中,您可以使用 (https://www.w3.org/TR/xslt-30/#built-in-templates-shallow-copy) 将标识转换声明为默认处理,然后只需为元素编写一个模板:<xsl:mode on-no-match="shallow-copy"/>
transform
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xpath-default-namespace="http://www.example.com/something"
xmlns="http://www.example.com/something"
exclude-result-prefixes="#all"
version="3.0">
<xsl:mode on-no-match="shallow-copy"/>
<xsl:template match="flow/transform">
<message>
<xsl:apply-templates select="@*, node()"/>
</message>
</xsl:template>
</xsl:stylesheet>
https://xsltfiddle.liberty-development.net/pPzifpw
在 XSLT 2 中,您必须将其拼写出来:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xpath-default-namespace="http://www.example.com/something"
xmlns="http://www.example.com/something"
exclude-result-prefixes="#all"
version="2.0">
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@*, node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="flow/transform">
<message>
<xsl:apply-templates select="@*, node()"/>
</message>
</xsl:template>
</xsl:stylesheet>
添加回答
举报