Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
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 August 17th, 2007, 11:20 AM
Authorized User
 
Join Date: Mar 2007
Posts: 33
Thanks: 0
Thanked 0 Times in 0 Posts
Default two different templates for same match attr?

Hi Folks!

Is there a way of having two templates matching the same child?
I want to use a xsl:when on my xsl:apply-templates tag.

For example:

<xsl:choose>
<xsl:when test="[test expression here]">
<xsl:apply-templates select="Time_AM"/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="Time_AM"/>
</xsl:otherwise>
</xsl:choose>

Now, the two templates (Time_AM and Time_PM) are pointing to the same node "Time" where I have attributes that will be use to select from for the test...

Thanks,
Gabi.


 
Old August 17th, 2007, 03:37 PM
Friend of Wrox
 
Join Date: May 2004
Posts: 109
Thanks: 18
Thanked 0 Times in 0 Posts
Default

You can add a 'mode' attribute to the templates with different values (say mode='AM' and mode='PM').
Then when you apply-template, use the correct mode to direct the processing to the desired template.

------------------------
GnuPG Key fingerprint = 1AD4 726D E359 A31D 05BF ACE5 CA93 7AD5 D8E3 A876

Michael Hare
 
Old September 6th, 2007, 10:48 AM
Authorized User
 
Join Date: Mar 2007
Posts: 33
Thanks: 0
Thanked 0 Times in 0 Posts
Default

mphare!

Thanks a lot! I read up on this subject but I have hard time comprehending it. Can you please scribble a short coding xsl example?

The idea is to basically apply a different template depending if the "slot" attribute in my XML example below has "am" or "pm" in it:

<Time slot="9:00 am"/>
<Time slot="1:00 pm"/>


MANY THANKS AGAIN!
Gabi.


 
Old September 6th, 2007, 10:56 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

<xsl:apply-template select="Time" mode="AM"/>

or

<xsl:apply-template select="Time" mode="PM"/>

and the templates look like:

<xsl:template match="Time" mode="AM">
    ...
</xsl:template>

<xsl:template match="Time" mode="PM">
    ...
</xsl:template>


/- Sam Judson : Wrox Technical Editor -/





Similar Threads
Thread Thread Starter Forum Replies Last Post
template match doesnt match the required node Tomi XSLT 2 March 12th, 2007 06:24 AM
Changing variables in match templates chicken XSLT 0 September 11th, 2006 10:26 AM
Match records bram_code VB Databases Basics 1 May 5th, 2006 10:36 AM
Elements that don't match any templates clareE XSLT 3 December 21st, 2005 06:20 AM
Help!! i need to get a closest match tseng Access VBA 3 February 4th, 2005 07:44 PM





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