【问题标题】:XSLT error: Cannot find a template named XXSLT 错误:找不到名为 X 的模板
【发布时间】:2019-03-22 12:19:37
【问题描述】:

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

找不到名为 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>

【问题讨论】:

  • 与您的问题无关:您可以使用 literal result elements 来简化代码 - 例如&lt;Document&gt; 而不是 &lt;xsl:element name="Document"&gt;。当名称需要在运行时动态计算时使用xsl:element

标签: xml xslt xslt-1.0


【解决方案1】:

改变

<xsl:template match="getIndex">

<xsl:template name="getIndex">
              ^^^^

一般:

  • 使用&lt;xsl:template match="模式"&gt; 代表xsl:apply-templates
  • 使用&lt;xsl:template name="名称"&gt; 代表xsl:call-template

【讨论】:

    猜你喜欢
    • 2020-07-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-27
    • 2021-09-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多