[xquery-talk] XPath Expression help

David Sewell dsewell at virginia.edu
Wed Jul 19 16:58:58 PDT 2006


If I understand your requirements, then you can use

 //key[not(. = 'AllowedKey1' or . = 'AllowedKey2' or . = 'AllowedKey3')]

to match an unrecognized key, or if you really need to return a boolean
true value, the expression

 boolean(//key[not(. = 'AllowedKey1' or . = 'AllowedKey2' or . = 'AllowedKey3')])

will return "true" if there is an unrecognized key. These are both legal
in XPath 1.0. (Presumably you're not using XQuery, since that supports
XPath 2.0 by definition.)

DS


On Wed, 19 Jul 2006, Todd Ditchendorf wrote:

> I realize this is an XQuery list, but I know that this list is particularly
> good at constructing tricky XPath expressions, so I hope you don't mind.
>
> I need some help constructing an XPath. I am currently restricted to XPath 1.0
> syntax.
>
> I have a document like this:
>
> <dict>
> <key>AllowedKey1</key>
> <value/>
> <key>AllowedKey2</key>
> <value/>
> <key>AllowedKey3</key>
> <value/>
> <key>UnrecognizedKey</key>
> <value/>
> </dict>
>
>
>
> So I have fixed set of allowed <key> element string-values  -- ('AllowedKey1',
> 'AllowedKey2', 'AllowedKey3')
>
> It is not required that all three be present. 0-unbounded allowed key values
> may be present.
>
> However, if there is a single key outside of that set, I would like to detect
> it.
>
> Can anyone create an XPath 1.0 expression that will return true if an
> unrecognized key string-value is present?
>
>
> Todd Ditchendorf
> Software Engineer
> itod at apple.com
>
>
>

-- 
David Sewell, Editorial and Technical Manager
Electronic Imprint, The University of Virginia Press
PO Box 400318, Charlottesville, VA 22904-4318 USA
Courier: 310 Old Ivy Way, Suite 302, Charlottesville VA 22903
Email: dsewell at virginia.edu   Tel: +1 434 924 9973
Web: http://www.ei.virginia.edu/


More information about the talk mailing list