[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Variables and the mode attribute in apply-template

Subject: RE: Variables and the mode attribute in apply-templates
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Thu, 3 Nov 2005 15:11:18 -0000
apply template mode
Nice try, a sort of double-polymorphism where the template to be executed
depends on two nodes rather than just one...

You could try

<xsl:apply-templates select="/content/layout/node()">
  <xsl:with-param name="p" select="xxx"/>
</xsl:apply-templates>

to call some kind of routing template which then applies templates to $p in
a particular (fixed) mode.

This feels to me like currying of functions, so it might be worth looking at
Dimitre Novatchev's FXSL library and seeing if that offers anything that
appeals.

The reason it doesn't work of course is that in any language there are some
places where you can use variables and some where you can't. You can't
dynamically compute the name of a function or template to be called, the
name of a mode, the name of a variable to be evaluated, the URI of a
stylesheet module to be included, the name of a type to use in an "instance
of" test, the text of an XPath expression to be evaluated, or the name of
the instruction that you want to execute next. Most of these get requested
from time to time (except the last - I made that one up). That's not to say
that none of these are potentially useful; though in my view higher-order
functions would meet most of the needs much more cleanly, and that's what
FXSL is offering.

Michael Kay
http://www.saxonica.com/ 

> -----Original Message-----
> From: ben senior [mailto:ben@xxxxxxxxxxxxx] 
> Sent: 03 November 2005 14:27
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  Variables and the mode attribute in apply-templates
> 
> I wish to decide between calling one of a set of templates 
> depending on
> a fragment of xml (/content/layout/node()).
> 
> Rather than having a mass of xsl:when/choose statements, I thought I
> would add :
> 
> <xsl:apply-templates select="xxx" mode="{/content/layout/node()}"/>
> 
> That didn't work. I then tried setting an xsl:variable and doing
> mode="$layout" and that didn't work.
> Then I tried setting the mode attribute using xsl:attribute and that
> didn't work.
> 
> Am I missing out on something at the conceptual level - is this to do
> with xsl's statelessness?
> 
> Regards,
> 
> Ben

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.