XSLT2.0一起工作,并尝试将相同的转换过程应用于输入XML的两个元素,并在XSLT中动态创建的元素。 输入XML:
<?xml version="1.0" encoding="UTF-8"?>
<document>
<h2>General Introduction</h2>
<h3>Project Overview</h3>
<h3>Goals and Challenges</h3>
<h2>Installation</h2>
<h3>Initial Configuration</h3>
<h4>Configuration File</h4>
<h3>Deployment</h3>
<h4>On a Local Server</h4>
<h4>On a Remote Server</h4>
<h2>Usage</h2>
<h3>Basic Commands</h3>
<h3>Advanced Options</h3>
</document>
XSLT
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/document">
<html>
<body>
<xsl:apply-templates/>
<h3>Dynamic title (was not in the XML)</h3>
</body>
</html>
</xsl:template>
<xsl:template match="h2 | h3 | h4">
<xsl:element name="{name()}">
¶<xsl:value-of select="."/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
issue
<h2>, <h3>, and <h4>
元素。 但是,动态创建的元素:
<h3>Dynamic title (was not in the XML)</h3>
不是由匹配
h2 | h3 | h4
的模板处理的。
问题如何确保XML元素和动态创建的元素都经历相同的转换过程? 是否有一种方法可以重新申请模板到XSLT中生成的元素?
将变量作为临时结果,并且可能更好的不同模式来分开处理步骤: