This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

RE: Shorthand for XPath expression


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]