【问题标题】:apply template in xslt not working as expected在 xslt 中应用模板未按预期工作
【发布时间】:2021-06-07 15:21:21
【问题描述】:

以下是输入输出 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>

【问题讨论】:

  • 我不明白您为什么要尝试匹配一个在您的 XML 中甚至不存在的 &lt;employee&gt; 元素...

标签: xml xslt xslt-2.0 xslt-3.0


【解决方案1】:

您只能将模板应用于存在但&lt;xsl:apply-templates select="employee"/&gt; 不会在您的输入样本中选择任何内容的节点。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-02-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-01
    • 1970-01-01
    • 2012-06-23
    相关资源
    最近更新 更多