Getting the document path in a collection using XQuery
Monday, 30 May 2011 · 2 messages
C
chas30 May 2011 05:03 #
Say I have a collection c with xml documents x.xml, y.xml, and z.xml and that I've added them using "to" so that they are found here:
collection('c/x')
...
Let's say that in each document I have a node <code/>, so in x.xml I have <code id='1'/>, in y.xml I have <code id='2'/>, etc.
I can query across the documents to find the <code/> node with id = 2 pretty easily. But now that I've found it, I want to do further queries limiting myself to that document. In other words, I want to learn using XQuery that the <code/> node with id = 2 is in collection('c/y').
How can I do this?
TIA,
Chas.
DP
Dimitar Popov30 May 2011 10:18 #
Hi Chas,
you could use the function
fn:document-uri(): http://www.w3.org/TR/xpath- functions/#func-document-uri . A working example which I tested with BaseX is
//code[@id = '2']/root()/document-uri()
Cheers,
DimitarQuoted text · 03:03:19 · 24 lines
Am Montag 30 Mai 2011, 03:03:19 schrieb chas at munat.com: > Say I have a collection c with xml documents x.xml, y.xml, and z.xml and > that I've added them using "to" so that they are found here: > > collection('c/x') > ... > > Let's say that in each document I have a node <code/>, so in x.xml I have > <code id='1'/>, in y.xml I have <code id='2'/>, etc. > > I can query across the documents to find the <code/> node with id = 2 > pretty easily. But now that I've found it, I want to do further queries > limiting myself to that document. In other words, I want to learn using > XQuery that the <code/> node with id = 2 is in collection('c/y'). > > How can I do this? > > TIA, > Chas. > > _______________________________________________ > BaseX-Talk mailing list > BaseX-Talk at mailman.uni-konstanz.de > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk
Written for BaseX 6.6. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery