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

Discussion in 'XML' started by Eshrath Ali Khan, Nov 9, 2004.

  1. 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






    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    Eshrath Ali Khan, Nov 9, 2004
    #1
    1. Advertising

  2. Eshrath Ali Khan

    Joris Gillis Guest

    > 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,

    --
    Joris Gillis (http://www.ticalc.org/cgi-bin/acct-view.cgi?userid=38041)
    Ceterum censeo XML omnibus esse utendum
     
    Joris Gillis, Nov 9, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tony Prichard
    Replies:
    0
    Views:
    791
    Tony Prichard
    Dec 12, 2003
  2. HANM
    Replies:
    2
    Views:
    767
    Joseph Kesselman
    Jan 29, 2008
  3. Konrad Hammerer
    Replies:
    14
    Views:
    631
    Jonathan N. Little
    Feb 7, 2008
  4. Replies:
    3
    Views:
    200
  5. Katie
    Replies:
    2
    Views:
    206
    Randy Webb
    Jul 20, 2006
Loading...

Share This Page