How to find out the position of a element in the XML Document

  • Thread starter Eshrath Ali Khan
  • Start date
E

Eshrath Ali Khan

Hi,

I have a requirement where I am transforming a XML into a html using
an XSL. I need to create a object for the each and every occurrence of
an element named "tgroup" in the xml. Also I need to assign a unique id
for this object based upon the its occurence in the xml document. (note:
the unique id should not be assigned depeneding upon its position with
respect to the parent element but with respect to its number of
occurence in the document).

This tgroup element can occur at n number of places in the xml document
and it not limited to occur within another element.

For example:

it is not only a child of a particular element but it can be a child of
other elements in the document tooo.

<root>
...
<A1>
<tgroup></tgroup>
.................
<A2>
<tgroup></tgroup>
<B1>
<tgroup></tgroup>
<B2>
<tgroup></tgroup>
<B3>
<tgroup></tgroup>

</root>

I have multiple xsl files which is use to transform this. So for each
and every occurence of a <tgroup> i need to create an object tag in the
target html with a unique id which I want as "tablecontrol1"
"tablecontrol2" "tablecontrol3" etcc..

Here 1, 2, 3 are the position of this element in the entire document. I
used the position() function of XPath to find out but it give the
position of the element in the context node only and not the position of
this element in the entire docuemnt.

Is there a way where I can find out the position of an element in the
entire document.

thanks
-Eshrath
 
J

Joris Gillis

I have a requirement where I am transforming a XML into a html using
an XSL. I need to create a object for the each and every occurrence of
an element named "tgroup" in the xml. Also I need to assign a unique id
for this object based upon the its occurence in the xml document. (note:
the unique id should not be assigned depeneding upon its position with
respect to the parent element but with respect to its number of
occurence in the document).

Hi,

Not sure it is the best method, but I think this should work:

<xsl:value-of select="count(preceding::tgroup)+1"/>

regards,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top