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.xs l' type='text/xsl'?>
<syntax xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespace SchemaLocation= "syntax.xsd ">
<syntaxrule>
<syntaxelement> function</syntaxelement>
<terms>
<non_terminal>k eyword</non_terminal>
<non_terminal>o pen_paren</non_terminal>
<non_terminal>l evel_expression </non_terminal>
<sequence min="0" max="1">
<definitions>
<terms>
<non_terminal>c omma</non_terminal>
<non_terminal>m ember_expressio n</non_terminal>
</terms>
</definitions>
</sequence>
<non_terminal>c lose_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_xq uery.xsl' type='text/xsl'?>
<syntax xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance">
<syntaxrule>
<syntaxelement> function</syntaxelement>
<terms>
<terminal>perio d</terminal>
<terminal>(</terminal>
<non_terminal>l evel_expression </non_terminal>
<sequence min="0" max="1">
<defintions>
<terms>
<non_terminal>c omma</non_terminal>
<non_terminal>m ember_expressio n</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('SE LECT SYNTAX_ELEMENT FROM
SYNTAX_ELEMENTS WHERE CATEGORY = ''symbol'' or CATEGORY =
''keyword''') for $element in db2-fn:sqlquery('SE LECT SYNTAX_ELEMENT
FROM SYNTAX_ELEMENTS WHERE CATEGORY = ''function'' AND ELEMENT_NAME =
''" + elementName + "''') return <syntaxrule>{$e lement/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!
having.
I have a bunch of xml files with format similar to the following:
<?xml-stylesheet href='syntax.xs l' type='text/xsl'?>
<syntax xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespace SchemaLocation= "syntax.xsd ">
<syntaxrule>
<syntaxelement> function</syntaxelement>
<terms>
<non_terminal>k eyword</non_terminal>
<non_terminal>o pen_paren</non_terminal>
<non_terminal>l evel_expression </non_terminal>
<sequence min="0" max="1">
<definitions>
<terms>
<non_terminal>c omma</non_terminal>
<non_terminal>m ember_expressio n</non_terminal>
</terms>
</definitions>
</sequence>
<non_terminal>c lose_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_xq uery.xsl' type='text/xsl'?>
<syntax xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance">
<syntaxrule>
<syntaxelement> function</syntaxelement>
<terms>
<terminal>perio d</terminal>
<terminal>(</terminal>
<non_terminal>l evel_expression </non_terminal>
<sequence min="0" max="1">
<defintions>
<terms>
<non_terminal>c omma</non_terminal>
<non_terminal>m ember_expressio n</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('SE LECT SYNTAX_ELEMENT FROM
SYNTAX_ELEMENTS WHERE CATEGORY = ''symbol'' or CATEGORY =
''keyword''') for $element in db2-fn:sqlquery('SE LECT SYNTAX_ELEMENT
FROM SYNTAX_ELEMENTS WHERE CATEGORY = ''function'' AND ELEMENT_NAME =
''" + elementName + "''') return <syntaxrule>{$e lement/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!