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

Matching on keys

Subject: Matching on keys
From: "Wendell Piez wapiez@xxxxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 6 Jan 2017 17:55:54 -0000
 Matching on keys
Hello XSL-List,

I am having more and more occasions these days to handle HTML @class
semantics, which as you probably know can be 'overloaded' in the sense
that multiple values (NMTOKEN) of 'class' may have to be distinguished
and handled separately.

An idiom for matching any element .foo (CSS selector) could be

<xsl:template match="*[tokenize(@class,'\s+')='foo')]">

This will match the element by virtue of the value being present on
the @class, split apart at white space and compared (many-to-one) with

(That logic can of course be relegated to a stylesheet function call
for neatness. It's true you can get an element matching more than one
template this way: that's the idea.)

Question: I can define a key, as in

<xsl:key name="elements-by-class" match="*[matches(@class,'\S')]"


<xsl:template match="key('elements-by-class','foo')">

I regard this as a neat trick, and think it might be an "improvement"
:-) but I suppose from one point of view at least, that may be

What do readers think? Should I prefer a stylesheet function instead?
(John Lumley what do you think?)


Wendell Piez | http://www.wendellpiez.com
XML | XSLT | electronic publishing
Eat Your Vegetables

Current Thread


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.
First Name
Last Name
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.