Problem with an XQuery statement

Discussion in 'XML' started by Cameron.MacNeil.024@gmail.com, Jun 6, 2008.

  1. Guest

    Hi folks, hopefully you'll be able to help me with this problem I'm
    having.

    I have a bunch of xml files with format similar to the following:

    <?xml-stylesheet href='syntax.xsl' type='text/xsl'?>
    <syntax xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="syntax.xsd">
    <syntaxrule>
    <syntaxelement>function</syntaxelement>
    <terms>
    <non_terminal>keyword</non_terminal>
    <non_terminal>open_paren</non_terminal>
    <non_terminal>level_expression</non_terminal>
    <sequence min="0" max="1">
    <definitions>
    <terms>
    <non_terminal>comma</non_terminal>
    <non_terminal>member_expression</non_terminal>
    </terms>
    </definitions>
    </sequence>
    <non_terminal>close_paren</non_terminal>
    </terms>
    </syntaxrule>
    </syntax>

    All of these xml files are stored in a db2 database. Also inside the
    database are other terms that I can match up with the non_terminal
    tags in these xml files. I used xquery to replace the <non_terminal>
    tags with terminal ones where applicable:

    <?xml-stylesheet href='syntax_xquery.xsl' type='text/xsl'?>
    <syntax xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <syntaxrule>
    <syntaxelement>function</syntaxelement>
    <terms>
    <terminal>period</terminal>
    <terminal>(</terminal>
    <non_terminal>level_expression</non_terminal>
    <sequence min="0" max="1">
    <defintions>
    <terms>
    <non_terminal>comma</non_terminal>
    <non_terminal>member_expression</non_terminal>
    </terms>
    </definitions>
    </sequence>
    <terminal>)</terminal>
    </terms>
    </syntaxrule>
    </syntax>

    The problem I'm having is that my xquery statement will only look at
    the non_terminal fields directly under the syntaxrule/terms tags, and
    not the ones under the sequence/definitions/terms tags. Does anyone
    know how I could adjust the query to find all of the non_terminal
    tags? My XQuery code is shown below.

    "XQUERY let $keyword := db2-fn:sqlquery('SELECT SYNTAX_ELEMENT FROM
    SYNTAX_ELEMENTS WHERE CATEGORY = ''symbol'' or CATEGORY =
    ''keyword''') for $element in db2-fn:sqlquery('SELECT SYNTAX_ELEMENT
    FROM SYNTAX_ELEMENTS WHERE CATEGORY = ''function'' AND ELEMENT_NAME =
    ''" + elementName + "''') return <syntaxrule>{$element/syntaxrule/
    syntaxelement} <terms>{for $term in $element/syntaxrule/terms/* return
    if (count(for $keyterm in $keyword where $keyterm/syntaxrule/
    syntaxelement = $term return $keyterm) >= 1) then for $keyterm in
    $keyword where $keyterm/syntaxrule/syntaxelement = $term return
    <terminal>{data($keyterm/syntaxrule/terms)}</terminal> else $term}</
    terms></syntaxrule>"

    Thanks alot!
    , Jun 6, 2008
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    3
    Views:
    802
  2. amessimon

    problem using xquery and asp.net

    amessimon, Mar 7, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    616
    amessimon
    Mar 9, 2005
  3. Jay McGavren
    Replies:
    11
    Views:
    1,130
    Alan Krueger
    Jan 16, 2006
  4. Bastian Gorke
    Replies:
    0
    Views:
    460
    Bastian Gorke
    Aug 14, 2003
  5. Replies:
    0
    Views:
    1,315
Loading...

Share This Page