468,247 Members | 1,310 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,247 developers. It's quick & easy.

Problem with an XQuery statement

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 27 '08 #1
0 1213

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Benjamin G. Jones | last post: by
8 posts views Thread by Clamps | last post: by
1 post views Thread by amessimon | last post: by
2 posts views Thread by tammo.mueller | last post: by
4 posts views Thread by Suma | last post: by
4 posts views Thread by Pascal Sartoretti | last post: by
reply views Thread by engelenfrederik | last post: by
reply views Thread by kermitthefrogpy | last post: by
reply views Thread by zattat | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.