Using the ID function in xpath expressions
Questions about XML that are not covered by the other forums should go here.
-
- Posts: 6
- Joined: Tue Sep 25, 2007 11:51 am
Using the ID function in xpath expressions
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!
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!
-
- Posts: 6
- Joined: Tue Sep 25, 2007 11:51 am
-
- Site Admin
- Posts: 2095
- Joined: Thu Jan 09, 2003 2:58 pm
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
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
-
- Posts: 6
- Joined: Tue Sep 25, 2007 11:51 am
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
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!

Return to “General XML Questions”
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service