Home > Archive > MS SQL XML > November 2006 > XQuery path to root









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author XQuery path to root
FH

2006-11-21, 7:16 pm

Hi,

I have a recursice XML, where articles can be child of other articles. I've
an xquery written, to find all the articles. Now I want also to know the path
to the root, so I can know at what level the article is situated. Below, an
example of my Xquery.

select XMLfile.query
('
<Sleepy>
{
for $i in //Product[@type="Article"]/ProductHeader/Header
return (($i/Name/text[@lang="NL"]),?)
}
</Sleepy>
')
from XMLInvoice
where Invoice = 999999

Can anyone help ?

Han

2006-11-24, 12:17 am

Hello

There is no way to retrieve the entire path of the context node from the
root without writing another recursive function or template. And generally
it is not needed because you can't use the xpath created dynamically at
runtime. See if some workarounds can help,

count of ancestors
count of ancestor Articles
name of parent

I am not sure, but cases are that your need come from bad XML structure.

"FH" <FH@discussions.microsoft.com> wrote in message
news:91C17C52-4CE9-408D-8835- 5D2D0B09921B@microso
ft.com...
> Hi,
>
> I have a recursice XML, where articles can be child of other articles.
> I've
> an xquery written, to find all the articles. Now I want also to know the
> path
> to the root, so I can know at what level the article is situated. Below,
> an
> example of my Xquery.
>
> select XMLfile.query
> ('
> <Sleepy>
> {
> for $i in //Product[@type="Article"]/ProductHeader/Header
> return (($i/Name/text[@lang="NL"]),?)
> }
> </Sleepy>
> ')
> from XMLInvoice
> where Invoice = 999999
>
> Can anyone help ?
>



Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com