2

I have a problem with call-template, I'm getting error:

Cannot find a template named getIndex

Syntax seems to be correct. I tried with apply-template and all was fine. I don't have any idea why this error appeared.

Here is example XSLT file:

<?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>
1
  • 3
    Unrelated to your question: you can simplify your code by using literal result elements - e.g. <Document> instead of <xsl:element name="Document">. Use xsl:element when the name needs to calculated dynamically at runtime. Commented Mar 22, 2019 at 12:48

1 Answer 1

6

Change

<xsl:template match="getIndex">

to

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

In general:

  • Use <xsl:template match="pattern"> for xsl:apply-templates.
  • Use <xsl:template name="name"> for xsl:call-template.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.