XPath 2.0 expression from XQuery?



Namaste, Y'all!

I've got a valid XQuery expression that I need to convert to XPath
2.0. This expression will be stored in a resource file and applied to
XML by a Java program with saxon8.jar (I'm pretty sure it's v.8.7).
The manifest from the jar file follows:
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.7.0
Created-By: 1.5.0_06-b05 (Sun Microsystems Inc.)
Project-Name: Saxon-B
Main-Class: net.sf.saxon.Transform

The question is, how can I convert this to an XPath 2.0 expression?
When I tried simply removing the <XTRACT> tags and outer curly-braces,
the Java 1.6 compiler informed me that "let" is not allowed in XPath.
Removing all these let's is daunting, if not impossible. And, once
I've done that, what other error messages will I encounter?

Is there a better way to do this?

Here's the XQuery:

<XTRACT>
{
let $bodyPosition := 3
for $r in doc("xtractorTest.xml")//BODY/descendant-or-self::*
let $node := concat(upper-case(string(node-name($r))),': ')
let $text := normalize-space(string($r/text()[1]))
let $subnodes := $r/*
let $attrs :=
for $a in $r/@*
return concat( $node, upper-case(string(node-name($a))),': ',$r/
data($a),'
')
let $node := string-join(for $n in $r/ancestor-or-self::*[position()
< last() - $bodyPosition]
return concat(upper-case(string(node-name($n))),': '),'' )
return
if (string-length($text) > 0) then concat($attrs, $node, $text,'
')
else $
attrs
}
</XTRACT>

What this does: for all sub-elements of <BODY>, it generates a string
that is something like breadcrumbs from the names of the elements and,
if appropriate, attribute, colon-delimited, followed by the text.

A brief example:
<BODY>
<Version Number="1"/>
<GEOGRAPHY Region="Middle East" altRegion="Near East">
<Sub-Region>Palestine</Sub-Region>
<Country>Israel
<LOCATION>West Bank<town>Bethlehem</town></LOCATION>
<LOCATION>Gaza Strip</LOCATION></Country>
</GEOGRAPHY>
<TOPIC language="English">INTERNATIONAL POLITICAL</TOPIC>
<TOPIC language="Hebrew">LEADER</TOPIC>
</BODY>

The XQuery generates:
VERSION: NUMBER: 1
GEOGRAPHY: REGION: Middle East
GEOGRAPHY: ALTREGION: Near East
GEOGRAPHY: SUB-REGION: Palestine
GEOGRAPHY: COUNTRY: Israel
GEOGRAPHY: COUNTRY: LOCATION: West Bank
GEOGRAPHY: COUNTRY: LOCATION: TOWN: Bethlehem
GEOGRAPHY: COUNTRY: LOCATION: Gaza Strip
TOPIC: LANGUAGE: English
TOPIC: INTERNATIONAL POLITICAL
TOPIC: LANGUAGE: Hebrew
TOPIC: LEADER

TIA,

Paul M Lieberman

.



Relevant Pages

  • Re: XPath 2.0 expression from XQuery?
    ... I've got a valid XQuery expression that I need to convert to XPath ... how can I convert this to an XPath 2.0 expression? ... GEOGRAPHY: ALTREGION: Near East ... GEOGRAPHY: COUNTRY: Israel ...
    (comp.text.xml)
  • Re: simple command line XML node manipulation tool?
    ... manipulate XML files. ... as arguments or input script file), a bit of xpath ... The XQuery would be something like this: ...
    (comp.text.xml)
  • Re: Native Xml Databases
    ... How do they compare with ordinary dbs? ... if you can do you process with XQuery, XPath and XUpdate you might consider to use it. ...
    (comp.lang.java.databases)
  • Re: Ive been curious out XQuery
    ... What is a user-defined function for XQuery? ... 2004 and 2005 Microsoft MVP C# ... > XPath 2.0 queries (disregarding the namespace bindings in the XQuery ... Many Microsoft MVP's agree and Stylus Studio is ...
    (microsoft.public.sqlserver.xml)

Loading