Using the ID function in xpath expressions

Questions about XML that are not covered by the other forums should go here.
bnz
Posts: 6
Joined: Tue Sep 25, 2007 11:51 am

Using the ID function in xpath expressions

Post by bnz »

Hello,

i have created an xml-schema where some elements "A" that have an "id" attribute of type xs:ID and other elements "B" reference this attribute using xs:IDREF. Lets call this attribute "idref". I have also added key and keyref elements which work fine for the validation by making sure that the referenced attribute values in B in fact do exist in A. However, i now want to do resolve the referenced node A from a path pointing to B. From what i understood, this sould work something like that for all B:

//B/id(@idref)/elementOfInterestInA

However, this construct does not work in the xpath builder nor in a small xsl file i created. Do you possibly have any idea what may be a common mistake here? Thanks for your answers!
bnz
Posts: 6
Joined: Tue Sep 25, 2007 11:51 am

Post by bnz »

by the way: i was about to check out the idref video demonstration to look for possible errors, but this video doesn't seem to work anymore?
bnz
Posts: 6
Joined: Tue Sep 25, 2007 11:51 am

Post by bnz »

I just played around with the included personnel sample. My testquery works against personal.xml where the dtd is included, but it doesn't against personal-schema.xml where the schema is used instead. Is id somehow outdated for schema? If so what is the correct method to resolve key references?
george
Site Admin
Posts: 2095
Joined: Thu Jan 09, 2003 2:58 pm

Post by george »

Hi,

The ID assignment is performed if the source specifies a DTD. If the source specifies a schema then you can use a schema aware processor, like Saxon 8 SA for instance (you need a separate license from Saxonica for that) - and you need to go to Options->Preferences -- XML -- XSLT-FO-XQuery -- XSLT -- Saxon -- Saxon 8 and enable the Schema based validation of the source file or the Lax schema based validation of the source file option from the Saxon8SA specific options.

The simpler alternative is to use keys instead of the id function. For instance in the case of the personal example that you mentioned you can define a key as

<xsl:key name="personById" match="person" use="@id"/>

then instead of id('someId') you can use key('personById', 'someId').

Best Regards,
George
George Cristian Bina
bnz
Posts: 6
Joined: Tue Sep 25, 2007 11:51 am

Post by bnz »

Thank you for answering Geroge! I wasn't aware that the processor must be schema-aware to support what i expected to be standard functionality :roll: I guess there is no free schema-aware procesor avaiable that is also supported by Oxygen? Also (waiting for the saxon8sa eval license to try it myself), i was wondering if the XSLT-FO-XQuery settings had any influence in the XPath-Builder support of the id() function in Oxygen. I had the impression that Saxon8SA is then only used for XSLT and XQuery. Anyway, I think i will simply use the key() solution you suggested. Thanks again!
Post Reply