[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Find elements where any attribute contains alpha-

Subject: Re: Find elements where any attribute contains alpha-numerical chars of an input string
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Fri, 02 Nov 2012 21:56:25 -0400
Re:  Find elements where any attribute contains  alpha-
At 2012-11-02 21:44 -0400, Graydon wrote:
On Fri, Nov 02, 2012 at 11:54:22PM +0100, Philipp Kursawe scripsit:
> I have this rather complex xpath:
>
> //element[@*[contains(translate(., translate(.,
> 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789', ''),
> ''), translate('string', translate('string',
> 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789', ''),
> ''))]]
>
> where "string" would be an input string with non-alpha chars and
> spaces and mixed letter cases.
> I would like to select any element whose attributes contain parts of
> the input string, stripped by non-alpha chars and whitespace.
>
> Problem is, the xpath does not work for mixed char input strings.

Wouldn't

//element[matches(@*,replace($string,'[\p{L}\p{Nd}]',''),'i')]

work?

Because of the cardinality of the first argument to matches(), not quite. It is expecting a singleton and you are supplying a sequence. You would have to restructure the expression and see if the following would satisfy the original poster's requirement:


//element[@*/matches(.,replace($string,'[\p{L}\p{Nd}]',''),'i')]

... remembering that:

$nodes/expression(.)

... is the same as:

for $n in $nodes return expression($n)

Thus, my replacement returns the sequence of Boolean values for the predicate.

Wait!! For a predicate, one cannot evaluate the effective Boolean value of a sequence of Boolean values, so I'm guessing now my first thought likely would not work.

So let's rewrite it as follows:

//element[@*[matches(.,replace($string,'[\p{L}\p{Nd}]',''),'i')]]

Now the data type of the predicate is a node set and there will be a non-empty node set of attribute nodes of the ones that satisfy the matches().

That would likely work better than my first thought. Assuming the matches() satisfies what the original poster wants.

I hope this helps. And I hope preserving my first mistaken thought is instructive, rather than just editing it out of my response.

. . . . . . . . . . Ken


-- Contact us for world-wide XML consulting and instructor-led training Free 5-hour lecture: http://www.CraneSoftwrights.com/links/udemy.htm Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Google+ profile: https://plus.google.com/116832879756988317389/about Legal business disclaimers: http://www.CraneSoftwrights.com/legal

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.