p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   XSLT (http://p2p.wrox.com/forumdisplay.php?f=86)
-   -   template calling (http://p2p.wrox.com/showthread.php?t=59956)

kgoldvas July 10th, 2007 06:57 AM

template calling
 
hello

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>
        <xsl:attribute name="apiNode">
            <xsl:value-of select="$apiNode"/>
        </xsl:attribute>
        <xsl:attribute name="apiImport">
            <xsl:value-of select="$apiImport"/>
        </xsl:attribute>
</xsl:template>
<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>
    <xsl:attribute name="display">
        <xsl:value-of select="$display"/>
    </xsl:attribute>
</xsl:template>

thank you



mhkay July 10th, 2007 07:16 AM

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"/>
  </xsl:attribute>
</xsl:if>

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference


All times are GMT -4. The time now is 12:18 AM.

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