How about:
if (string(.) != '') then string-length(.) le 10 else false()
That requires casting the context to a string twice but calculating
string-length() once.
Or
matches(., '..?.?.?.?.?.?.?.?')
(Can I do that with '..?{0,10}'? Reviewing the syntax it looked like the
quantifier could only be a single digit.)
Cheers,
Eliot
On July 26, 2016 at 7:01 AM "Wolfgang Laun
wolfgang(_dot_)laun(_at_)gmail(_dot_)com"
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> wrote:
Just for fun:
string-length() idiv 2 le 5
Optimization by obfuscation. Phooey.
-W
On 26 July 2016 at 13:55, Martin Honnen martin(_dot_)honnen(_at_)gmx(_dot_)de
<
xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> wrote:
On 26.07.2016 13:51, Costello, Roger L. costello(_at_)mitre(_dot_)org wrote:
I need an XPath expression which returns true if the string in <A> is
between 1 and 10 characters in length, and false otherwise.
For example, the XPath expression should return true on this XML:
<A>hi</A>
Here's an inefficient XPath expression:
(string-length(.) gt 0) and (string-length(.) le 10)
It's inefficient because it computes the string length twice.
Is there a more efficient XPath expression to solve this problem?
Well, in XPath 3 you can use
let $l := string-length()
return ($l gt 0 and $l le 10)
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--