Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4324636
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T09:09:34+00:00 2026-05-21T09:09:34+00:00

I have searched all around to find a solution to my problem, but i

  • 0

I have searched all around to find a solution to my problem, but i just got more questions…

consider the following XML:

<dynamicStuff>
      <dyn id="name1">...</dyn>
      <dyn id="name2">...</dyn>
      <dyn id="name3">...</dyn>
      <dyn id="name4">...</dyn> 
</dynamicStuff>

and suppose the I have an XSLT file as follows:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

     <xsl:template name="name1">    
         ...
     </xsl:template>

     <xsl:template name="name2">    
         ...
     </xsl:template>

     <xsl:template name="name3">    
         ...
     </xsl:template>

     <xsl:template name="name4">    
         ...
     </xsl:template>

</xsl:stylesheet>

What I want to do is from a SECOND XSLT file dynamically determine which template to call with something like this:

<xsl:variable name="templateName">
     <xsl:value-of select="dyn/@id"/>
</xsl:variable>

<xsl:call-template name="$templateName"/>

sadly its not working, believe me when I say that I have tried a lot of different stuff, though it sounds so simple it does not work either…

Am I missing something?

Edit:

I have successfully done the following:

<xsl:template name="staticName">
    <xsl:param name="id" />

    <xsl:if test="$id = 'name1'">....</xsl:if>
    <xsl:if test="$id = 'name2'">....</xsl:if>
    ...
</xsl:template>

Calling in this way:

<xsl:call-template name="staticName">
     <xsl:with-param name="id" select="@id"/>
</xsl:call-template>

Needles to say how inconvenient this is… first of all my code will be bound to that staticName (imagine I need to do this call in a dozen files)… second I will have a bunch of (un)related content inside the same template when it could be more separated… a nightmare to upgrade the system u.u

It does what I want but not in the way I need…

Thanks in advance for any light on this matter!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T09:09:34+00:00Added an answer on May 21, 2026 at 9:09 am

    From http://www.w3.org/TR/xslt#named-templates

    The value of the name attribute is a
    QName,
    which is expanded as described in
    [2.4 Qualified
    Names
    ].

    It means that is neither an expression nor an AVT.

    Explicit xsl:call-template instructions are fine whether by logic instructions or pattern matching like:

    <xsl:template match="dyn[@id='name1']" mode="dynamic">
     <xsl:call-template name="name1"/>
    </xsl:template>
    

    Another approach is named template references…

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:variable name="vTemplate" select="document('')/*/xsl:template"/>
        <xsl:template match="dyn">
            <xsl:apply-templates select="$vTemplate[@name = current()/@id]"/>
        </xsl:template>
        <xsl:template match="xsl:template[@name='name1']"
                      name="name1"> one </xsl:template>
        <xsl:template match="xsl:template[@name='name2']"
                      name="name2"> two </xsl:template>
        <xsl:template match="xsl:template[@name='name3']"
                      name="name3"> three </xsl:template>
        <xsl:template match="xsl:template[@name='name4']"
                      name="name4"> four </xsl:template>
    </xsl:stylesheet> 
    

    Output:

     one  two  three  four 
    

    Note: Because this technique uses document('') to process the XSLT rather than the original XML file, the original document being processed is not available in the named templates. However, you can explicitly pass current() as parameter to the templates if needed:

        <xsl:template match="dyn">
            <xsl:apply-templates select="$vTemplate[@name = current()/@id]">
                <xsl:with-param name="current" select="current()"/>
            </xsl:apply-templates>
        </xsl:template>
    

    If needed, $current can be used to access the original document:

        <xsl:template match="xsl:template[@name='name1']" name="name1">
            <xsl:param name="current"/>
            <xsl:value-of select="$current/@id"/>
            <xsl:text> becomes one</xsl:text> 
        </xsl:template>
    

    If needed, $current could be re-established as current node using for-each:

    <xsl:template match="xsl:template[@name='name2']" name="name2">
        <xsl:param name="current"/>
        <xsl:for-each select="$current">
                <xsl:value-of select="@id"/>
                <xsl:text> becomes two</xsl:text>
        </xsl:for-each>
    </xsl:template>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have searched it all around but couldn't find it all i want to
I've searched around for a solution to my problem but couldn't find one so
I have searched all morning and yesterday afternoon and still cannot find an solution
I have read the documentation and searched all over but I can't find how
I've searched around, and saw some tips, but still couldn't find the solution to
I searched around and couldn't find a solution to this problem. I am trying
I have searched around for an answer to this but can't find one. When
I have searched many threads so far but cant seem to find a solution.
I have searched around for possible answers, but did not find one that came
I have searched online but all the answers I have found were very primitive.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.