xsl-list
[Top] [All Lists]

Re: [xsl] Find elements where any attribute contains alpha-numerical chars of an input string

2012-11-02 18:12:02
On Fri, 2012-11-02 at 23:54 +0100, Philipp Kursawe wrote:

I would like to select any element whose attributes contain parts of
the input string, stripped by non-alpha chars and whitespace.

One way might be to build up a sequence of each run of consecutive
alphanumeric characters from $input, and find atttributes that match
each such run in turn.

//@*[contains(., "sock")]

will find all attributes containing "sock", including "hassocks".

I'm not sure if that's what you want, or if you only want whole word
matches. So, if $input is "dry sock" it should match attributes
containing the string "dry" or the string "sock", or both - e.g.
   <pew items="sundry hassocks" />

You also don't say if it's XPath 1, 2 or 3, and if it's inside XSLT or
not. It makes quite a difference. If you're using libxml2, it's XPath 1.
If you're using Saxon 8 or later, it's XPath 2. If you're using Gravel
1.2, it's actually a garden path and not XPath at all :-)

Liam

-- 
Liam Quin - XML Activity Lead, W3C, http://www.w3.org/People/Quin/
Pictures from old books: http://fromoldbooks.org/
Ankh: irc.sorcery.net irc.gnome.org freenode/#xml
Co-author, 5th edition of "Beginning XML", Wrox, July 2012


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--