Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
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
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old June 24th, 2011, 03:13 PM
Friend of Wrox
Points: 470, Level: 7
Points: 470, Level: 7 Points: 470, Level: 7 Points: 470, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2004
Location: Plano, TX, USA.
Posts: 109
Thanks: 18
Thanked 0 Times in 0 Posts
Arrow Is there a way to match multiple modes in one template?

I am using Saxon 9 on Windows 7/64 in a cygwin bash shell.

I have a chain of templates that process using a mode="import" on each template.
Somewhere near the end of the chain I would like to diverge the processing to a different template for certain cases. These cases are known at the start of the chain, so what I want to do is something like:

Code:
<xs:template match="A" mode="a | b">
  <xs:apply-templates select="B" mode="#current"/>
</>

<xs:template match="B" mode="a | b">
  <xs:apply-templates select="C" mode="#current"/>
</>

<!-- here I diverge -->

<xs:template match="C" mode="a">
   <xs:apply-templates select="D" mode="#current"/>
 </>
 
<xs:template match="C" mode="b">
   <xs:apply-templates select="E" mode="#current"/>
 </>
I know I have severely butchered the syntax in favour of brevity, but I hope you get the idea.

In reality my chain is much deeper than this. When I start I know if I want the D or the E behavour, so I can start out using the mode a or b and use the same templates up until I get to the end where a or b will select the D or E template path.

My other alternatives are to write parallel templates for a and for b, or to consider refactoring my code to do the processing a different way.
__________________
------------------------
Keep Moving Forward

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

Michael Hare
Reply With Quote
  #2 (permalink)  
Old June 24th, 2011, 07:01 PM
mhkay's Avatar
Wrox Author
Points: 18,274, Level: 58
Points: 18,274, Level: 58 Points: 18,274, Level: 58 Points: 18,274, Level: 58
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,932
Thanks: 0
Thanked 282 Times in 277 Posts
Default

The mode attribute of xsl:template is a space-separated list of mode names.

I'm surprised that you found it difficult to find this information in the spec or in reference books.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
Reply With Quote
The Following User Says Thank You to mhkay For This Useful Post:
mphare (June 28th, 2011)
  #3 (permalink)  
Old June 28th, 2011, 03:52 PM
Friend of Wrox
Points: 470, Level: 7
Points: 470, Level: 7 Points: 470, Level: 7 Points: 470, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2004
Location: Plano, TX, USA.
Posts: 109
Thanks: 18
Thanked 0 Times in 0 Posts
Default

The spec doesn't indicate that a list was even possible. Section 5.7 just says the value of the modes must match and what happens if they do not.
Your book does indicate that a list is possible, but I didn't understand how the list items were delimited, hence my question here.

Thanks for the help!
__________________
------------------------
Keep Moving Forward

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

Michael Hare
Reply With Quote
  #4 (permalink)  
Old June 28th, 2011, 04:09 PM
samjudson's Avatar
Friend of Wrox
Points: 8,687, Level: 40
Points: 8,687, Level: 40 Points: 8,687, Level: 40 Points: 8,687, Level: 40
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 2,133
Thanks: 1
Thanked 189 Times in 188 Posts
Default

The spec states: "... its value must be a non-empty whitespace-separated list of tokens, each of which defines a mode to which the template rule is applicable."

http://www.w3.org/TR/xslt20/#dt-mode
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
Reply With Quote
  #5 (permalink)  
Old June 28th, 2011, 04:18 PM
Friend of Wrox
Points: 470, Level: 7
Points: 470, Level: 7 Points: 470, Level: 7 Points: 470, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2004
Location: Plano, TX, USA.
Posts: 109
Thanks: 18
Thanked 0 Times in 0 Posts
Default

Well, that's my problem - I'm looking at the 1.0 spec.

Thanks, for the heads up. Sam.

- m
__________________
------------------------
Keep Moving Forward

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

Michael Hare
Reply With Quote
  #6 (permalink)  
Old November 8th, 2017, 07:39 AM
Registered User
Points: 6, Level: 1
Points: 6, Level: 1 Points: 6, Level: 1 Points: 6, Level: 1
Activity: 66%
Activity: 66% Activity: 66% Activity: 66%
 
Join Date: Nov 2017
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

If I'm reading correctly, the description of the value of the @mode attribute for <xsl:apply-templates> in the fourth edition says "Lexical QName or «#current»". For what it's worth, I was confused by the singular QName as well, and I'm grateful for the clarification here.
Reply With Quote
  #7 (permalink)  
Old November 9th, 2017, 11:49 AM
Registered User
Points: 6, Level: 1
Points: 6, Level: 1 Points: 6, Level: 1 Points: 6, Level: 1
Activity: 66%
Activity: 66% Activity: 66% Activity: 66%
 
Join Date: Nov 2017
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

... which, of course, makes sense, since <xsl:apply-templates> can select only one mode at a time. I was looking in the wrong place in the book. Doh!
Reply With Quote
Reply


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
template match heightsofdelites XSLT 3 May 27th, 2010 05:01 AM
Param in template match=" " iceandrews XSLT 2 May 7th, 2008 08:37 AM
value-of inside template match RoeZ XSLT 5 April 17th, 2008 01:09 PM
template match doesnt match the required node Tomi XSLT 2 March 12th, 2007 07:24 AM
help with xsl template match enT XSLT 9 September 24th, 2003 07:21 AM



All times are GMT -4. The time now is 03:29 AM.


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