Sign In/My Account | View Cart  
advertisement

Article:
 XQuery and Data Abstraction
Subject: The slash operator
Date: 2007-07-25 06:46:34
From: ajwelch


Hi Kurt,


Good article. I know the examples are contrived to make your point, but a great feature of XPath 2.0 that you didn't mention is the slash operator.


This means you can rewrite:


for $para in //p return
if(string-length($para)>800) then string-length($para) else ( )


to:


for $para in //p return
$para[string-length()>800]/string-length()


which is the same as:


//p[string-length()>800]/string-length()


...and because we're only interested in the length of the

and not the para itself, that can be reduced to:


//p/string-length()[. > 800]


The slash operator applies the function on its right to each node in the sequence on its left - so //p creates a sequence of all the

elements in the document, then the string-length() function is applied to each item in that sequence using the slash operator resulting in a sequence of integers , and finally that sequence is filtered using the predicate to contain only those values greater than 800.


cheers
andrew
http://andrewjwelch.com



Previous Message Previous Message   Next Message No Next Message


Sponsored By: