Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
| Search | Today's Posts | Mark Forums Read
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old October 27th, 2006, 02:08 PM
Registered User
Join Date: Aug 2006
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Using Parameter to call another template

I'm trying to use a param to be the name of the next template I call:

For instance, this code works fine:

<xsl:template name="preprinted-form">
<fo:table table-layout="fixed" space-before.optimum="0pt" space-after.optimum="0pt">
<xsl:call-template name="sales-order-columns"/>

I want to be able to do this:
<xsl:template name="preprinted-form">
<xsl:param name="column_prg"/>
<fo:table table-layout="fixed" space-before.optimum="0pt" space-after.optimum="0pt">
    <xsl:call-template name="$column_prg"/>

So I can make the call:
<xsl:call-template name="preprinted-form">
<xsl:with-param name="column_prg" select="sales-order-columns"/>

Is this possible? Or anything like it?
Currently, this gives and error:
XTSE0280: Invalid QName {$column_prg}

Here is what sales-order-columns contains:
<xsl:template name="sales-order-columns">
        <fo:table-column column-width="0.8in" />
        <fo:table-column column-width="0.45in" />
        <fo:table-column column-width="1.35in" />
        <fo:table-column column-width="3.35in" />
        <fo:table-column column-width="0.70in" />
        <fo:table-column column-width="0.45in" />
        <fo:table-column column-width="0.80in" />

The idea of this is because I am overlaying tables on top of one another. I want to be able to create this template so that it can be used on many business forms.

I am using saxon8.jar with jre1.5.0_06.
Old October 27th, 2006, 03:08 PM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts

Nice idea but it doesn't work. The template name in call-template must be supplied literally as a QName.

If you want a dynamic call it can usually be achieved using apply-templates. Take a look at Dimitre Novatchev's FXSL library for an extreme example of what can be achieved without departing from the XSLT standard.

Michael Kay
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference

Similar Threads
Thread Thread Starter Forum Replies Last Post
Difference between call-template ,apply-templates vikkiefd XSLT 4 March 12th, 2008 05:09 AM
anyway to call a template with a lower precedence? ojasrege XSLT 3 November 30th, 2007 12:13 PM
how to use call-template result in a test? briforge XSLT 6 February 13th, 2006 06:54 PM
xsl:call-template name="$variable" problem chemi XSLT 1 October 6th, 2005 07:28 AM
import / call / template match Kabe XSLT 3 February 26th, 2004 11:31 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.