Altova Mailing List ArchivesProblem with an XQuery statementTo: NULL Date: 6/6/2008 4:37:00 AM 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! | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
