(: Copyright (c)2005 Elsevier, Inc. : : Licensed under the Apache License, Version 2.0 (the "License"); : you may not use this file except in compliance with the License. : You may obtain a copy of the License at : : http://www.apache.org/licenses/LICENSE-2.0 : : Unless required by applicable law or agreed to in writing, software : distributed under the License is distributed on an "AS IS" BASIS, : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. : See the License for the specific language governing permissions and : limitations under the License. : : The use of the Apache License does not indicate that this project is : affiliated with the Apache Software Foundation. :) (:---------------------------------------------------------------------------------------------------------------- : : This script translates the W3C XPath F&O into xqDoc XML. : The script assumes the W3C XPath F&O html file found at : : http://www.w3c.org/TR/2003/WD-xpath-functions-20030502 : : has been loaded into the XML database with a URI value of : : 'xpath-html' : : The generated xqDoc XML will be loaded into the 'xqdoc' collection with : a URI value of 'http://www.w3.org/2003/05/xpath-functions'. : : This script translates the W3C XPath Functions and Operators specification (May 2003) : into xqDoc XML. There are certainly more recent drafts available for the W3C XPath Functions : and Operators specification, but we are using the May 2003 version since the XML database we : are leveraging supports the May 2003 specification. It would be a simple exercise to create : a similar translation script for more recent versions of the XPath Functions and : Operators specification. : :----------------------------------------------------------------------------------------------------------------:) define function get-text($item as item()) as xs:string* { if ($item instance of element()) then for $i in $item/node() return get-text($i) else if ($item instance of text()) then xs:string($item) else () } let $uri := "http://www.w3c.org/TR/2003/WD-xpath-functions-20030502" let $xml := { current-dateTime() } N/A http://www.w3.org/2003/05/xpath-functions This is the xqDoc XML version for the W3C XPath Functions and Operators Working Draft for May 2003. Since the information contained in the xqDoc XML version is only a subset of the W3C Working Draft, the W3C version should be consulted for the complete explanation. All of the functions below contain helpful links (see:) that will lead the user to the particular function defined in the W3C XPath Functions and Operators Working Draft for May 2003. {$uri} 02 May 2003 { let $seq := (for $x in doc("xpath-html")//*:div[@class="div3"] [.//*:div[@class="exampleInner"] //*:div[@class="proto"] //*:code[@class="function"] /text()[starts-with(.,"fn:")]] order by xs:string($x/*:h4/*:a/@name) ascending return $x, for $y in doc("xpath-html")//*:div[@class="div2"] [./*:h3/*:a/@name[starts-with(.,"func-")]] [.//*:div[@class="exampleInner"] //*:div[@class="proto"] //*:code[@class="function"] /text()[starts-with(.,"fn:")]] order by xs:string($y/*:h3/*:a/@name) ascending return $y, for $z in doc("xpath-html")//*:div[@class="div1"] [./*:h2/*:a/@name[starts-with(.,"func-")]] [.//*:div[@class="exampleInner"] //*:div[@class="proto"] //*:code[@class="function"] /text()[starts-with(.,"fn:")]] order by xs:string($z/*:h2/*:a/@name) ascending return $z) for $i in $seq return { for $p in $i/*:p return get-text($p) } { for $a in distinct-values($i//*:div[@class="exampleInner"] /*:div[@class="proto"] //*:code[@class="arg"]) return {$a} } {concat($uri,"#",xs:string($i/(*:h4 | *:h3 | *:h2)/*:a/@name), ";;", if (starts-with(xs:string($i/(*:h4 | *:h3 | *:h2)/*:a/@name), "func-xpath-")) then substring-after(xs:string($i/(*:h4 | *:h3 | *:h2)/*:a/@name), "func-xpath-") else substring-after(xs:string($i/(*:h4 | *:h3 | *:h2)/*:a/@name), "func-") )} { if (starts-with(xs:string($i/(*:h4 | *:h3 | *:h2)/*:a/@name), "func-xpath-")) then {substring-after(xs:string($i/(*:h4 | *:h3 | *:h2)/*:a/@name), "func-xpath-")} else {substring-after(xs:string($i/(*:h4 | *:h3 | *:h2)/*:a/@name), "func-")} } { for $s in $i//*:div[@class="exampleInner"]/*:div[@class="proto"] return {concat("define function ", substring-after(xs:string(data($s)), "fn:"))} } } return (: insert proprietary logic to store document into the database :) (: $xml is the node to insert :) (: "http://www.w3.org/2003/05/xpath-functions" is the URI :)