This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: Shorthand for XPath expression
- To: xsl-list at lists dot mulberrytech dot com
- Subject: RE: [xsl] Shorthand for XPath expression
- From: Wendell Piez <wapiez at mulberrytech dot com>
- Date: Thu, 19 Jul 2001 11:00:25 -0400
- References: <F991D4265D6AD4119A1900508BC98E57CF778F@NTEXCL01>
- Reply-To: xsl-list at lists dot mulberrytech dot com
William,
At 07:55 PM 7/18/01, Chris wrote:
>William,
>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
<local:names>
<name>bob</name>
<name>joe</name>
<name>ben</name>
</local:names>
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
test="@name=$names"
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.
Cheers,
Wendell
======================================================================
Wendell Piez mailto:wapiez@mulberrytech.com
Mulberry Technologies, Inc. http://www.mulberrytech.com
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: http://www.mulberrytech.com/xsl/xsl-list