[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] 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')]"> ... </xsl:template> 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')]" use="tokenize(@class,'\s+')"/> then <xsl:template match="key('elements-by-class','foo')"> ... </xsl:template> 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 arguable. What do readers think? Should I prefer a stylesheet function instead? (John Lumley what do you think?) Regards, Wendell -- Wendell Piez | http://www.wendellpiez.com XML | XSLT | electronic publishing Eat Your Vegetables _____oo_________o_o___ooooo____ooooooo_^
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|