RE: [xsl] Shorthand for XPath expression

Subject: RE: [xsl] Shorthand for XPath expression
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Thu, 19 Jul 2001 11:00:25 -0400

At 07:55 PM 7/18/01, Chris wrote:
No. But you can do test=contains('bob-joe-ben', @name)

And if you want to be super-careful about it, you can amend this to:

test="contains(('bob-joe-ben', @name) and not(contains(@name, '-'))"

Of course this won't work if any of your names contains your delimiter (so use a different one).

You can't quite do

><xsl:if test="@name in ('bob', 'joe', 'ben')">

because XSL (XPath) has no notion of sets, exactly. Although it does have node sets. Which leads to the technique of keeping your list in an XML fragment (in the stylesheet or elsewhere) and then getting it as a node set. So you could do


at the top level of your stylesheet (don't forget to declare the "local" namespace). Then bind this node set to a variable, as in

<xsl:variable name="names" select="document('')/*/local:names/name"/>

and then you can do


which will test true if any of the nodes in $names has string-value equal to @name. (Do we have a name for this idiom, anyone?)

This is good when things get hairy; use Chris's technique when things are light.


====================================================================== Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx Mulberry Technologies, Inc. 17 West Jefferson Street Direct Phone: 301/315-9635 Suite 207 Phone: 301/315-9631 Rockville, MD 20850 Fax: 301/315-8285 ---------------------------------------------------------------------- Mulberry Technologies: A Consultancy Specializing in SGML and XML ======================================================================

XSL-List info and archive:

Current Thread