xquery question.. how 2 if possible get tuples that have any attributes or elements of a given value

J

Jeff Kish

Just wondering if it was possible to xquery an xml file
to retrieve all elements that had a given text value
or all elements where any attribute had a value of interest.

I guess I could figure out a roughshod way to get the elements but I'm not sure about the attributes



Thanks
 
D

David Carlisle

Jeff Kish said:
Just wondering if it was possible to xquery an xml file
to retrieve all elements that had a given text value
//*[.='value']

or all elements where any attribute had a value of interest.
//*[@*='value']

I guess I could figure out a roughshod way to get the elements but I'm not sure about the attributes



Thanks


David
 
J

Jeff Kish

Jeff Kish said:
Just wondering if it was possible to xquery an xml file
to retrieve all elements that had a given text value
//*[.='value']

or all elements where any attribute had a value of interest.
//*[@*='value']

I guess I could figure out a roughshod way to get the elements but I'm not sure about the attributes



Thanks


David
Thank you David.
 
J

Jeff Kish

Jeff Kish said:
Just wondering if it was possible to xquery an xml file
to retrieve all elements that had a given text value
//*[.='value']

or all elements where any attribute had a value of interest.
//*[@*='value']

I guess I could figure out a roughshod way to get the elements but I'm not sure about the attributes



Thanks


David
Is there a way to access the element type?
For example, if the where clause filters out unwanted elements,
can I somehow output just the type of element we found things in, rather than the entire element?

I would guess in some other language it would be elementName() or some such function.

so
for $b in document("labrep.xml")//presentation
for $a in $b//*[@*="ByContract"]
return
<theAttribute>
{$a/text(), $a/@*}
</theAttribute>

I could somehow return "tabletag" if it was found in element <tabletag
id="ByContract">...</tabletag>
 
D

David Carlisle

I would guess in some other language it would be elementName() or some such function.

name() or local-name() if you want to ignore namespace prefixes)

This is all Xpath 1, not really anything new in Xquery, although that is
true of most of Xquery, really.

David
 
J

Jeff Kish

name() or local-name() if you want to ignore namespace prefixes)

This is all Xpath 1, not really anything new in Xquery, although that is
true of most of Xquery, really.

David
Thanks. I'm still coming up to speed, and it is hard to find things out
because there is so much information.. I just need to study example after
example, and look over the docs.

thank you once again
Jeff Kish
 
J

Jeff Kish

name() or local-name() if you want to ignore namespace prefixes)

This is all Xpath 1, not really anything new in Xquery, although that is
true of most of Xquery, really.

David
I must be getting old in my thick age.
I don't seem to be getting anything from this, and I expected the name of the
element, so maybe you could tell me how I bolluxed up either the syntax, use,
or if my expectations are wrong...? I thought name($b) would return the
element name, i.e. "<dialog>" in the first case, and some other in the next
two.

for $b in document("labrep.xml")//*[@*="ByWorkord"]
return
<temp>{$b/@*, name($b), local-name($b), namespace-uri($b)}</temp>

returns this data


<temp id="ByWorkord"
label="label1"
mboname="MBO1"
width="900"
height="380">dialog dialog </temp>,
<temp id="byworkorder_time_table"
label="label2"
parentmbo="MBO2"
relationship="RELATIONSHIP1"
</temp>,
<temp id="aclaborwo"
label="label3"
parentdatasrc="datasrc1"
relationship="RELATIONSHIP2"
dialog </temp>



Thanks
Jeff Kish
 
D

David Carlisle

Jeff Kish said:
I must be getting old in my thick age.
I don't seem to be getting anything from this, and I expected the name of the
element, so maybe you could tell me how I bolluxed up either the syntax, use,
or if my expectations are wrong...? I thought name($b) would return the
element name, i.e. "<dialog>" in the first case, and some other in the next
two.
for $b in document("labrep.xml")//*[@*="ByWorkord"]
return
<temp>{$b/@*, name($b), local-name($b), namespace-uri($b)}</temp>

returns this data


<temp id="ByWorkord"
label="label1"
mboname="MBO1"
width="900"
height="380">dialog dialog </temp>,
<temp id="byworkorder_time_table"
label="label2"
parentmbo="MBO2"
relationship="RELATIONSHIP1"
</temp>,
<temp id="aclaborwo"
label="label3"
parentdatasrc="datasrc1"
relationship="RELATIONSHIP2"
dialog </temp>



Thanks
Jeff Kish


well without the input I can only guess, but teh name of an element
thatuses a start tag of <dialog> is dialog not <dialog> and local-name
is the same if you are not using namespaces.
I would guess that the first temp above is the correct output.
You generae a temp element node, copy the attribute nodes (which will
appear as attributes in the start tag when serialised) then you
{$b/@*,
then you make a sequence of three strings
name($b), local-name($b), namespace-uri($b)
when you linearise such a sequence you put spaces between each string so
you end up with

dialog dialog

The second <temp< element is not well formed, presumably a cut and paste
wrong.

David
 
J

Jeff Kish

well without the input I can only guess, but teh name of an element
thatuses a start tag of <dialog> is dialog not <dialog> and local-name
is the same if you are not using namespaces.
I would guess that the first temp above is the correct output.
You generae a temp element node, copy the attribute nodes (which will
appear as attributes in the start tag when serialised) then you
{$b/@*,
then you make a sequence of three strings
name($b), local-name($b), namespace-uri($b)
when you linearise such a sequence you put spaces between each string so
you end up with

dialog dialog

The second <temp< element is not well formed, presumably a cut and paste
wrong.

David
Thanks.. I understand a bit more now.
Well, if you have any more time...

I want to see if I can get the element name (i.e. "book" in this case) of the
elements with any attribute of value "1992".

I'm getting the entire element <book> in all its glory.. I'd like to just get
the "name" of the element that has the attributes, not of its child elements
also.


If I use the input below (books.xml)

and I I submit this query

for $b in document("books.xml")//*[@*="1992"]
return
<temp>{$b/@*, $b/.[name()]}</temp>


{-- results in this output
<temp year="1992">
<book year="1992">a1992<title>Advanced Programming in the UNIX
Environment</title>
<author>
<last>Stevens</last>
<first>W.</first>
</author>
<publisher>Addison-Wesley</publisher>
<price>65.95</price>
</book>
</temp>
--}






books.xml:

<bib>
<book year="1994">a1994 <title>TCP/IP Illustrated</title>
<author>
<last>Stevens</last>
<first>W.</first>
</author>
<publisher>Addison-Wesley</publisher>
<price>65.95</price>
</book>
<book year="1992">a1992<title>Advanced Programming in the UNIX
Environment</title>
<author>
<last>Stevens</last>
<first>W.</first>
</author>
<publisher>Addison-Wesley</publisher>
<price>65.95</price>
</book>
<book year="2000">a2000<title>Data on the Web</title>
<author>
<last>Abiteboul</last>
<first>Serge</first>
</author>
<author>
<last>Buneman</last>
<first>Peter</first>
</author>
<author>
<last>Suciu</last>
<first>Dan</first>
</author>
<publisher>Morgan Kaufmann Publishers</publisher>
<price>65.95</price>
</book>
<book year="1999">a1999<title>The Economics of Technology and Content
for Digital TV</title>
<editor>
<last>Gerbarg</last>
<first>Darcy</first>
<affiliation>CITI</affiliation>
</editor>
<publisher>Kluwer Academic Publishers</publisher>
<price>129.95</price>
</book>
</bib>

Jeff Kish
 
D

David Carlisle

you want the name of $b nwhich is name($b) you have $b/.[name()] which
is the same as $b[name()] which is the same as $b whenever the predicate
[name()] is true, and since name() returns a string not a boolean it's
true if the string is non-empty, ie always, as element names are always
non empty. so itreturns the whole element node b (which includes all
descendents etc)

typing even worse than usual as 1 year old "helping"

David (and Matthew)
 
J

Jeff Kish

you want the name of $b nwhich is name($b) you have $b/.[name()] which
is the same as $b[name()] which is the same as $b whenever the predicate
[name()] is true, and since name() returns a string not a boolean it's
true if the string is non-empty, ie always, as element names are always
non empty. so itreturns the whole element node b (which includes all
descendents etc)

typing even worse than usual as 1 year old "helping"

David (and Matthew)
Keep those 1 year olds in the loop!
Thanks
I'll look it over more
 
J

Jeff Kish

you want the name of $b nwhich is name($b) you have $b/.[name()] which
is the same as $b[name()] which is the same as $b whenever the predicate
[name()] is true, and since name() returns a string not a boolean it's
true if the string is non-empty, ie always, as element names are always
non empty. so itreturns the whole element node b (which includes all
descendents etc)

typing even worse than usual as 1 year old "helping"

David (and Matthew)
I see it is case sensitive, i.e. if I search for any element with any attribute named "ByRecord" it
won't find one named "byRecord". Anyway to get by that? I'm searching the docs also...
Thanks again. OH.. I have 18, 14, 8 so I know about helping hands!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,241
Members
46,831
Latest member
RusselWill

Latest Threads

Top