XSLT 错误:找不到名为 X 的模板

Szc*_*pan 2 xml xslt xslt-1.0

我的调用模板有问题,出现错误:

找不到名为 getIndex 的模板

语法似乎是正确的。我试过了apply-template,一切都很好。我不知道为什么会出现这个错误。

这是示例 XSLT 文件:

<?xml version="1.0" encoding="utf-8"?>
<!-- Created with Liquid Studio 2019 (https://www.liquid-technologies.com) -->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" indent="yes"/>

    <xsl:template match="/">
        <xsl:apply-templates/>
    </xsl:template>

    <xsl:template match="Document">
        <xsl:element name="Document">
            <xsl:apply-templates/>
        </xsl:element>
    </xsl:template>

    <xsl:template match="Produkt">
        <xsl:element name="Produkt">
            <xsl:element name="Index">
                <xsl:call-template name="getIndex"/>
            </xsl:element>
        </xsl:element>
    </xsl:template>

    <xsl:template match="getIndex">
        <xsl:value-of select="Index"/>
    </xsl:template>

</xsl:stylesheet>
Run Code Online (Sandbox Code Playgroud)

kjh*_*hes 5

改变

<xsl:template match="getIndex">
Run Code Online (Sandbox Code Playgroud)

<xsl:template name="getIndex">
              ^^^^
Run Code Online (Sandbox Code Playgroud)

一般来说:

  • 使用<xsl:template match="模式">进行xsl:apply-templates
  • 使用<xsl:template name="名称">xsl:call-template