Hello,
I've been trying to use the Xpath v2.0 function fn:id() but it doesn't run
well.I don't know if I use it in a bad way or if the Xquery processors don't
support it. I think there aren't any encoding problems and I also think I
use this function in a good way.
I enclose the files that I use in my examples. The example is very stupid
however it's very easy for testing the id() function. I have a xs:IDREFS
attribute called "people" in the "departament" element and I want to
retrieve their xs:ID that are in the element person. After that, I print
whatever to check if I run well.
XML-Document
<?xml version="1.0" encoding="UTF-8"?>
<document xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="schema.xsd">
<people>
<person id="id1" name="John"/>
<person id="id2" name="Peter"/>
<person id="id3" name="Anne"/>
</people>
<departaments>
<departament nam="Computer" people="id1 id2"/>
<departament nam="Business" people="id2 id3"/>
</departaments>
</document>
XQuery Document
xquery version "1.0";
<data>{
for $s in doc("example.xml")/document/departaments/departament
let $b2:=id($s/@people)/@name
return <depart>{
if ($b2='John') then $s/@nam
else ()
}</depart>
}</data>
XML_Schema
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
<xs:element name="departament">
<xs:complexType>
<xs:attribute name="nam" type="xs:string" use="required"/>
<xs:attribute name="people" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
<xs:element name="departaments">
<xs:complexType>
<xs:sequence>
<xs:element ref="departament" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="document">
<xs:complexType>
<xs:sequence>
<xs:element ref="people"/>
<xs:element ref="departaments"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="people">
<xs:complexType>
<xs:sequence>
<xs:element ref="person" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="person">
<xs:complexType>
<xs:attribute name="id" type="xs:ID" use="required"/>
<xs:attribute name="name" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
</xs:schema>
Thanks for all,
Luis
-------------------------------------------------------
This SF.Net email is sponsored by Yahoo.
Introducing Yahoo! Search Developer Network - Create apps using Yahoo!
Search APIs Find out how you can build Yahoo! directly into your own
Applications - visit http://developer.yahoo.net/?fr=offad-ysdn-ostg-q22005
|