[xquery-talk] Returning "pre-pos" context

David Carlisle davidc at nag.co.uk
Thu Jan 5 17:28:24 PST 2006



> find the tags that contains some data beginning with d (for example) on the
> ORTH tag - Ok You guys already helped me with that

note that Xquery (like XSLT and Xpath) has no access to the tags in a
document, only to the tree structure produced by parsing those tags.
I assume you mean element rather than tag. tag doesn't mean element, the
content of the tag <s> is "s". The content of the element s is the
sequence of white space and tok elements.

> What I would like to do, is to find the BB, but with the AA and the CC with
> it, so the final return value would be like: AA BB CC.

Not sure what you want returned, just those three strings or the 3 orth
elements containing those, or the three tok elements containing those
orth elements. I'll assume the last of these, in which case, perhaps

/s/tok[orth='BB']/(preceding-sibling::*[1],.,following-sibling::*[1])

assuming your processor supports the sibling axes (if not these can
always be rewritten to use <<)

If you want just the sequence of strings AA BB CC then:

/s/tok[orth='BB']/(preceding-sibling::*[1],.,following-sibling::*[1])/string(orth)


saxon produces

$ saxon8q -s tok.xml tok.xq
<?xml version="1.0" encoding="UTF-8"?>
<tok>
                              <orth>AA</orth>
                              <lex>
                                   <ctag>XX</ctag>
                              </lex>
                         </tok>
<tok>
                              <orth>BB</orth>
                              <lex>
                                   <ctag>YY</ctag>
                              </lex>
                         </tok>
<tok>
                              <orth>CC</orth>
                              <lex>
                                   <ctag>ZZ</ctag>
                              </lex>
                         </tok>

for the first expression and


$ saxon8q -s tok.xml tok.xq
<?xml version="1.0" encoding="UTF-8"?>AA BB CC


for the second

David



________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________


More information about the talk mailing list