Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: obtain element name, or attribute and value of the document name itself, and some elemnts and attributes from an ancestor or the node itself using xquery

From: kishjeff <jkish@--.---.--->
To: NULL
Date: 10/30/2008 10:43:00 AM
On Oct 30, 11:29=A0am, kishjeff <jk...@us.ibm.com> wrote:
> On Oct 30, 8:53=A0am, Martin Honnen <mahotr...@yahoo.de> wrote:
>
>
>
> > Jeff Kish wrote:
> > > xxx.xml
>
> > > segment speed=3D"1"
> > > table1 relation=3D"upper"
> > > table3 relation=3D"upper"
>
> > > xxy.xml
> > > segment speed=3D"2"
> > > table2 relation=3D"lower"
>
> > > given this xml file set:
>
> > > document xxx.xml
>
> > > <area>
> > > <segment id=3D"segment1" speed=3D"1">
> > > <table id=3D"table1" =A0relation=3D"upper" =A0 =A0/>
> > > <table id=3D"table2" =A0orientation=3D"side" />
> > > <table id=3D"table3" =A0relation=3D"upper" =A0 />
> > > </segment>
> > > </area>
>
> > > document xxy.xml
>
> > > <area>
> > > <segment id=3D"segment1" speed=3D"2">
> > > <table id=3D"table1" =A0orientation=3D"bottom" =A0 =A0/>
> > > <table id=3D"table2" =A0relation=3D"lower" />
> > > <table id=3D"table3" =A0orientation"top" =A0 />
> > > </segment>
> > > </area>
>
> > Here is an example XQuery,
>
> > string-join(
> > for $d in
> > collection('.?select=3Dtest20081030*.xml')[descendant::table[@relation]=
]
> > return
> > =A0 =A0(tokenize(base-uri($d), '/')[last()], '',
> > =A0 =A0concat('segment speed=3D"',
> > $d//table[@relation]/ancestor::segment/@speed, '"'),
> > =A0 =A0for $t in $d//table[@relation]
> > =A0 =A0return concat($t/@id, ' relation=3D"', $t/@relation, '"'), '')
> > , '&#10;')
>
> > that returns the described result when run with Saxon 9 in a working
> > directory that contains the input files as test20081030nn.xml
> > --
>
> > =A0 =A0 =A0 =A0 Martin Honnen
> > =A0 =A0 =A0 =A0http://JavaScript.FAQTs.com/
>
> Thanks. I'm using IPSI XQuery Interpreter v.1.3.4 which may be a bit
> long in the tooth (I don't think it is complete as I could not get
> starts-with to work) - let me give this a fly.
>
> thanks much Martin.
>
> Jeff

This was soooo helpful, thanks.
I have a related question..

I tried using this for fun  (notice the extra base-uri($d) in the
beginning of the last
return statement):

string-join(
for $d in
collection('.?select=3Dtest20081030*.xml')[descendant::table[@relation]]
return
   base-uri($d),(tokenize(base-uri($d), '/')[last()], '',
   concat('segment speed=3D"',
$d//table[@relation]/ancestor::segment/@speed, '"'),
   for $t in $d//table[@relation]
   return concat($t/@id, ' relation=3D"', $t/@relation, '"'), '')
, '&#10;')

I noticed that when I use this instead,  I get the error:

  XPST0008: XQuery static error in #...ri($d),(tokenize(base-
uri($d),#:
    Variable $d has not been declared
Static error(s) in query




transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent