以下是输入输出xml以及xslt和预期结果
输入xml-
<?xml version="1.0"?>
<data>
<name>Cat</name>
<sal>1</sal>
</data>
xslt与模板:-
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<Details>
<EmployeeName>
<xsl:apply-templates select="employee"/>
</EmployeeName>
</Details>
</xsl:template>
<xsl:template match="employee">
<TEST>
<xsl:value-of select="'CAT'"/>
</TEST>
</xsl:template>
</xsl:stylesheet>
输出获取:-
<?xml version="1.0" encoding="UTF-8"?><Details><EmployeeName/></Details>
预期输出:-
<?xml version="1.0" encoding="UTF-8"?>
<Details>
<EmployeeName>
<TEST>CAT</TEST>
</EmployeeName>
</Details>
您只能将模板应用于存在的节点,但<xsl:apply-templates select="employee"/>
不会在您的输入示例中选择任何内容。