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 July 10th, 2007, 06:57 AM
Authorized User
Join Date: Jan 2006
Location: tel aviv, israel, Israel.
Posts: 59
Thanks: 0
Thanked 0 Times in 0 Posts
Default template calling


I have 2 templates that look pretty the same with one different. in one there is attribute apiNode and in the other there isnt.
I would like to make out of them one template that with an 'if' function I would know which to call (the one with the apiNode or the one with out). in a simple words, is there a function that will check if there is apiNode (boolean or something)
this are the 2 templates
<xsl:template name="group-column">
    <xsl:param name="key" select="''"/>
    <xsl:param name="apiNode" select="''"/>
    <xsl:param name="apiImport" select="''"/>
        <xsl:attribute name="key">
            <xsl:value-of select="$key"/>
        <xsl:attribute name="apiNode">
            <xsl:value-of select="$apiNode"/>
        <xsl:attribute name="apiImport">
            <xsl:value-of select="$apiImport"/>
<xsl:template name="generalKeyDisplay">
    <xsl:param name="key" select="''"/>
    <xsl:param name="display" select="''"/>
    <xsl:attribute name="key">
        <xsl:value-of select="$key"/>
    <xsl:attribute name="display">
        <xsl:value-of select="$display"/>

thank you

Old July 10th, 2007, 07:16 AM
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

Well, there seems to be more than one difference to me: one template is outputting key, apiNode, and apiImport, while the other is outputting key and display. To me, there doesn't seem to be enough commonality to justify making a single template with conditional logic. But you can always do it if you want: create a single template with four parameters and four calls on xsl:attribute, each surrounded by xsl:if:

<xsl:if test="$key != ''">
  <xsl:attribute name="key">
    <xsl:value-of select="$key"/>

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
calling template with javascript smys123 XSLT 3 November 22nd, 2007 04:13 AM
template calling kgoldvas XSLT 1 August 1st, 2007 10:20 AM
calling template from a href bergs77 XSLT 4 January 9th, 2006 01:11 PM
calling one template in other template VijayKumar XSLT 3 September 15th, 2005 11:12 AM

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