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 December 17th, 2008, 06:28 PM
Authorized User
Join Date: Jun 2003
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to rushman
Default predicates and variables in match attribute

Hi all!

Let's say we have this XML:

<treat type="ice-cream">
<treat type="ice-cream">
<treat type="yogurt">

My question is: can I use a variable in the match attribute of a template? Something like this:

<xsl:variable name="myPreferredTreat" select="'yogurt'"/>

<xsl:template match="treat[@type = $myPreferredTreat]">
<xsl:value-of select="concat(flavour, ' ', @type)"/>


Dijkstra's law on Programming and Inertia:

If you don't know what your program is supposed to do, don't try to write it.
Old December 17th, 2008, 07:33 PM
mhkay's Avatar
Wrox Author
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts

It's allowed in XSLT 2.0 but not in XSLT 1.0.

Though I believe at least one XSLT 1.0 processor (Xalan) does actually allow it, despite it being illegal according to the spec.
Michael Kay
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
Old December 18th, 2008, 12:54 AM
Friend of Wrox
Join Date: Jun 2008
Posts: 291
Thanks: 9
Thanked 29 Times in 29 Posts

You are right Mike. It works with Xalan if written in XSLT 1.0. I tested in oXygen editor with different processors.

Similar Threads
Thread Thread Starter Forum Replies Last Post
variables in predicates barski XSLT 2 August 2nd, 2007 09:59 AM
Match by attribute. ole_v2 XSLT 6 November 11th, 2006 10:24 AM
Changing variables in match templates chicken XSLT 0 September 11th, 2006 10:26 AM
Match element based on attribute of child? transom XSLT 1 September 11th, 2005 03:26 PM
document(), attribute and name() match perropicante XSLT 8 November 17th, 2004 07:14 AM

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