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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jeff Kish

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

    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


  • David Carlisle

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

    Jeff Kish <kishjjrjj@prov ide.net> writes:
    [color=blue]
    > Just wondering if it was possible to xquery an xml file
    > to retrieve all elements that had a given text value[/color]

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

    //*[@*='value'][color=blue]
    >
    > I guess I could figure out a roughshod way to get the elements but I'm not sure about the attributes
    >
    >
    >
    > Thanks[/color]


    David

    Comment

    • Jeff Kish

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

      On Tue, 19 Oct 2004 08:55:41 GMT, David Carlisle <davidc@nag.co. uk> wrote:
      [color=blue]
      >Jeff Kish <kishjjrjj@prov ide.net> writes:
      >[color=green]
      >> Just wondering if it was possible to xquery an xml file
      >> to retrieve all elements that had a given text value[/color]
      >
      >//*[.='value']
      >[color=green]
      >> or all elements where any attribute had a value of interest.[/color]
      >
      >//*[@*='value'][color=green]
      >>
      >> I guess I could figure out a roughshod way to get the elements but I'm not sure about the attributes
      >>
      >>
      >>
      >> Thanks[/color]
      >
      >
      >David[/color]
      Thank you David.

      Comment

      • Jeff Kish

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

        On Tue, 19 Oct 2004 08:55:41 GMT, David Carlisle <davidc@nag.co. uk> wrote:
        [color=blue]
        >Jeff Kish <kishjjrjj@prov ide.net> writes:
        >[color=green]
        >> Just wondering if it was possible to xquery an xml file
        >> to retrieve all elements that had a given text value[/color]
        >
        >//*[.='value']
        >[color=green]
        >> or all elements where any attribute had a value of interest.[/color]
        >
        >//*[@*='value'][color=green]
        >>
        >> I guess I could figure out a roughshod way to get the elements but I'm not sure about the attributes
        >>
        >>
        >>
        >> Thanks[/color]
        >
        >
        >David[/color]
        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("labre p.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>

        Comment

        • David Carlisle

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

          [color=blue]
          > I would guess in some other language it would be elementName() or some such function.[/color]

          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

          Comment

          • Jeff Kish

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

            On Tue, 19 Oct 2004 13:59:00 GMT, David Carlisle <davidc@nag.co. uk> wrote:
            [color=blue]
            >[color=green]
            >> I would guess in some other language it would be elementName() or some such function.[/color]
            >
            >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[/color]
            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

            Comment

            • Jeff Kish

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

              On Tue, 19 Oct 2004 13:59:00 GMT, David Carlisle <davidc@nag.co. uk> wrote:
              [color=blue]
              >[color=green]
              >> I would guess in some other language it would be elementName() or some such function.[/color]
              >
              >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[/color]
              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("labre p.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">di alog dialog </temp>,
              <temp id="byworkorder _time_table"
              label="label2"
              parentmbo="MBO2 "
              relationship="R ELATIONSHIP1"
              </temp>,
              <temp id="aclaborwo"
              label="label3"
              parentdatasrc=" datasrc1"
              relationship="R ELATIONSHIP2"
              dialog </temp>



              Thanks
              Jeff Kish

              Comment

              • David Carlisle

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

                Jeff Kish <jeff.kish@mro. com> writes:
                [color=blue]
                > On Tue, 19 Oct 2004 13:59:00 GMT, David Carlisle <davidc@nag.co. uk> wrote:
                >[color=green]
                > >[color=darkred]
                > >> I would guess in some other language it would be elementName() or some such function.[/color]
                > >
                > >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[/color]
                > 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.
                >[/color]
                [color=blue]
                > for $b in document("labre p.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">di alog dialog </temp>,
                > <temp id="byworkorder _time_table"
                > label="label2"
                > parentmbo="MBO2 "
                > relationship="R ELATIONSHIP1"
                > </temp>,
                > <temp id="aclaborwo"
                > label="label3"
                > parentdatasrc=" datasrc1"
                > relationship="R ELATIONSHIP2"
                > dialog </temp>
                >
                >
                >
                > Thanks
                > Jeff Kish[/color]


                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

                Comment

                • Jeff Kish

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

                  <snip>[color=blue]
                  >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[/color]
                  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">a19 92<title>Advanc ed Programming in the UNIX
                  Environment</title>
                  <author>
                  <last>Stevens </last>
                  <first>W.</first>
                  </author>
                  <publisher>Addi son-Wesley</publisher>
                  <price>65.95</price>
                  </book>
                  </temp>
                  --}






                  books.xml:

                  <bib>
                  <book year="1994">a19 94 <title>TCP/IP Illustrated</title>
                  <author>
                  <last>Stevens </last>
                  <first>W.</first>
                  </author>
                  <publisher>Addi son-Wesley</publisher>
                  <price>65.95</price>
                  </book>
                  <book year="1992">a19 92<title>Advanc ed Programming in the UNIX
                  Environment</title>
                  <author>
                  <last>Stevens </last>
                  <first>W.</first>
                  </author>
                  <publisher>Addi son-Wesley</publisher>
                  <price>65.95</price>
                  </book>
                  <book year="2000">a20 00<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>Morg an Kaufmann Publishers</publisher>
                  <price>65.95</price>
                  </book>
                  <book year="1999">a19 99<title>The Economics of Technology and Content
                  for Digital TV</title>
                  <editor>
                  <last>Gerbarg </last>
                  <first>Darcy</first>
                  <affiliation>CI TI</affiliation>
                  </editor>
                  <publisher>Kluw er Academic Publishers</publisher>
                  <price>129.95 </price>
                  </book>
                  </bib>

                  Jeff Kish

                  Comment

                  • David Carlisle

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



                    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)

                    Comment

                    • Jeff Kish

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

                      On Wed, 20 Oct 2004 22:03:41 GMT, David Carlisle <davidc@nag.co. uk> wrote:
                      [color=blue]
                      >
                      >
                      >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)[/color]
                      Keep those 1 year olds in the loop!
                      Thanks
                      I'll look it over more

                      Comment

                      • Jeff Kish

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

                        On Wed, 20 Oct 2004 22:03:41 GMT, David Carlisle <davidc@nag.co. uk> wrote:
                        [color=blue]
                        >
                        >
                        >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)[/color]
                        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!

                        Comment

                        Working...