You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xalan.apache.org by Miroslav Nachev <mi...@space-comm.com> on 2002/01/28 17:23:24 UTC
How to get specific parent value
Hi,
I have the following XML Tree:
<doc>
<pages>
<page id="pg_1">
</page>
<page id="pg_2">
<chapter>
<article>
<article>
<article>
</article>
</article>
<article>
<article>
<article>
</article>
</article>
</article>
</article>
</chapter>
</page>
<page id="pg_3">
</page>
</pages>
</doc>
I have some XSL transformation file and when I am in the position
"<article>" I would like to see on which page ID I am. Can some body
help me? How to get the current parent with name "page"? In my case I
don't know on which level of article element I am !!!
Best Regards,
Miroslav Nachev
Re: How to get specific parent value
Posted by John Keyes <jo...@yahoo.com>.
This XPath should do the trick:
ancestor::*[name()='page'][@id]/@id
-John K
Miroslav Nachev wrote:
> Hi,
>
> I have the following XML Tree:
> <doc>
> <pages>
> <page id="pg_1">
> </page>
> <page id="pg_2">
> <chapter>
> <article>
> <article>
> <article>
> </article>
> </article>
> <article>
> <article>
> <article>
> </article>
> </article>
> </article>
> </article>
> </chapter>
> </page>
> <page id="pg_3">
> </page>
> </pages>
> </doc>
>
> I have some XSL transformation file and when I am in the position
> "<article>" I would like to see on which page ID I am. Can some body
> help me? How to get the current parent with name "page"? In my case I
> don't know on which level of article element I am !!!
>
>
> Best Regards,
> Miroslav Nachev
>
>
>
Re: How to get specific parent value
Posted by Gene Roske <Ge...@Computer.org>.
Miroslav -
Within a stylesheet, you can use the XPath location path ancestor::page
to get the page node that contains the current article.
- Gene Roske
Miroslav Nachev wrote:
>
> Hi,
>
> I have the following XML Tree:
> <doc>
> <pages>
> <page id="pg_1">
> </page>
> <page id="pg_2">
> <chapter>
> <article>
> <article>
> <article>
> </article>
> </article>
> <article>
> <article>
> <article>
> </article>
> </article>
> </article>
> </article>
> </chapter>
> </page>
> <page id="pg_3">
> </page>
> </pages>
> </doc>
>
> I have some XSL transformation file and when I am in the position
> "<article>" I would like to see on which page ID I am. Can some body
> help me? How to get the current parent with name "page"? In my case I
> don't know on which level of article element I am !!!
>
>
> Best Regards,
> Miroslav Nachev