Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XML
|
XML General XML discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XML section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 28th, 2006, 11:09 AM
Authorized User
 
Join Date: Jun 2003
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default Xquery storing all elements called 'id'

As 'id' is a special function in Xquery I believe. Is there a way to reference this node in Xquery. Ie:

<assets>
  <asset>
    <id>1</id>
  </asset>
  <asset>
    <id>2</id>
  </asset>
</assets>

$allAssets := $currentDoc/assets/asset/id
 
Old July 28th, 2006, 04:15 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

The id() function in XQuery selects nodes that, in the language of the XDM data model, have the "is-id" property. In practice a node can be given this property in three ways:

* by declaring an attribute of type ID in a DTD

* by declaring an element or attribute of type xs:ID in the schema

* by naming an attribute xml:id.

The fact that your elements are named <id> does not give them this property, or make them special in any other way. So you select them and process them exactly as you would an element called foo.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old July 31st, 2006, 07:47 AM
Authorized User
 
Join Date: Jun 2003
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hmm interesting. I was using a default namespace created by someone else and when i was counting the id elements it was returning 0 (incorrect). I've managed to fix this now by using the namespaces explictly for each path and now it works, whether this is a flaw or just my lack of understanding I dont know but I saw this with Ipedo's Xquery implementation.

Thanks
Ash





Similar Threads
Thread Thread Starter Forum Replies Last Post
Xalan v. Saxon and Xquery Camer XSLT 5 May 26th, 2009 12:44 PM
XQuery from command line Tomi XSLT 2 January 16th, 2008 01:58 PM
security on Xquery Tomi XSLT 3 May 7th, 2007 07:34 AM
How to get a XQuery.msi ? goldensaying XML 1 December 13th, 2006 01:01 PM
XQuery sonicDace XML 2 March 19th, 2004 05:45 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.