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 June 24th, 2011, 02:13 PM
Friend of Wrox
 
Join Date: May 2004
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
 
Old June 24th, 2011, 06:01 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 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
The Following User Says Thank You to mhkay For This Useful Post:
mphare (June 28th, 2011)
 
Old June 28th, 2011, 02:52 PM
Friend of Wrox
 
Join Date: May 2004
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
 
Old June 28th, 2011, 03:09 PM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
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?
 
Old June 28th, 2011, 03:18 PM
Friend of Wrox
 
Join Date: May 2004
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
 
Old November 8th, 2017, 07:39 AM
Registered User
 
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.
 
Old November 9th, 2017, 11:49 AM
Registered User
 
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!





Similar Threads
Thread Thread Starter Forum Replies Last Post
template match heightsofdelites XSLT 3 May 27th, 2010 04:01 AM
Param in template match=" " iceandrews XSLT 2 May 7th, 2008 07:37 AM
value-of inside template match RoeZ XSLT 5 April 17th, 2008 12:09 PM
template match doesnt match the required node Tomi XSLT 2 March 12th, 2007 06:24 AM
help with xsl template match enT XSLT 9 September 24th, 2003 06:21 AM





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