xsl-list
[Top] [All Lists]

Re: [xsl] XPath expression which checks that a string is between 1 and 10 characters in length?

2016-07-26 10:04:52
What is the purpose of making “efficient” source code?

I don’t think it is a good idea to assume that some kind of source code 
“efficiency” will result in execution or other efficiency.

I did a really trivial test and found no execution time difference between using

            
<result><xsl:value-of select="count(data/w[boolean(string-length(.)[. > 0 and . 
&lt; 11])])"/></result>

and

<result><xsl:value-of select="count(data/w[string-length(.) > 0 and 
string-length(.) &lt; 10])"/></result>


The “inefficient” code here

[string-length(.) > 0 and string-length(.) &lt; 10]


has the property that it is completely obvious what it is testing...


Dan





On 7/26/16, 7:51 AM, "Costello, Roger L. costello(_at_)mitre(_dot_)org" 
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> wrote:

Hi Folks,

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?

/Roger
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1340029
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--

<Prev in Thread] Current Thread [Next in Thread>