View Single Post
  #1 (permalink)  
Old June 24th, 2011, 03:13 PM
mphare mphare is offline
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:

<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