Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register | FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Display Modes
  #1 (permalink)  
Old February 10th, 2006, 06:30 AM
Friend of Wrox
Points: 651, Level: 9
Points: 651, Level: 9 Points: 651, Level: 9 Points: 651, Level: 9
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Jan 2006
Location: Ennis, Clare, Ireland.
Posts: 127
Thanks: 8
Thanked 0 Times in 0 Posts
Default Templates


I have inherited the following code contained within a XSL stylesheet:


 <xsl:element name="ShippingInstructions">
        <xsl:attribute name="ShippingType">Delivery</xsl:attribute>
    <xsl:copy-of select="./*"></xsl:copy-of>

  <xsl:template match="/">

  <xsl:template match="*">
      <xsl:when test="@ShippingType='Collection'">
        <xsl:call-template name="ShippingType"/>
        <xsl:call-template name="copy"/>

  <xsl:template name="copy">
      <xsl:for-each select="@*">


What I want to do is check through the document as above but execute another template outside of the '<xsl:template match="*">' statement if the XML document contains a date or time element (i.e. DateAdd Template (See below)).

<xsl:template match ="DateAdd">

   <xsl:call-template name="DateAdd">
      <xsl:with-param name="Date">20060214 07:00</xsl:with-param>

Can you help me code a statement to check each template or XML element whereby:
1. Template is equal to 'DateAdd'
2. Template is not equal to 'DateAdd'

AND would this mean replacing the '<xsl:template match="*">' statement?

Can someone please help with an example couple of lines. I'm still quite new to XML/XSL.



A Northern Soul

A Northern Soul
Reply With Quote
  #2 (permalink)  
Old February 10th, 2006, 06:54 AM
mhkay's Avatar
Wrox Author
Points: 18,356, Level: 59
Points: 18,356, Level: 59 Points: 18,356, Level: 59 Points: 18,356, Level: 59
Activity: 60%
Activity: 60% Activity: 60% Activity: 60%
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,943
Thanks: 0
Thanked 286 Times in 281 Posts

Firstly, I hate to see a template rule whose whole body is an xsl:choose. Split

<xsl:template match="*">
      <xsl:when test="@ShippingType='Collection'">
        <xsl:call-template name="ShippingType"/>
        <xsl:call-template name="copy"/>


<xsl:template match="*">
    <xsl:call-template name="copy"/>


<xsl:template match="*[@ShippingType='Collection']">
   <xsl:call-template name="ShippingType"/>

and then simplify further, because a template can have both a name and a match pattern so you can do:

<xsl:template name="ShippingType" match="*[@ShippingType='Collection']">

Then you can just add your match="DateAdd" template as another rule. There's a built-in set of priority rules if the same element matches multiple rules, for example match="XYZ[A='2']" takes precedence over match="XYZ" which takes precedence over match="*". But if things get more complicated (or if you want to be explicit) you can attach explicit priorities with the "priority" attribute.

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

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
"templates" Somesh ASP.NET 2.0 Professional 8 March 27th, 2007 08:53 AM
Templates pilcher85 Dreamweaver (all versions) 1 March 21st, 2007 05:51 PM
Templates Won't Apply neilac333 XSLT 5 October 26th, 2006 01:39 PM
Templates ervinel Classic ASP Basics 0 July 13th, 2006 02:47 PM
Class templates shenku ASP.NET 1.0 and 1.1 Professional 1 May 10th, 2005 08:32 AM

All times are GMT -4. The time now is 04:52 PM.

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