XSLT: absolute array-of-positions of a node... ?

Discussion in 'XML' started by Ivan_G_S, Jan 22, 2008.

  1. Ivan_G_S

    Ivan_G_S Guest

    Hello community!

    I'm looking for a possibility to create a kind of URL, which
    represents the absolute path to a node.

    I have an XML document with multiple-nested paragraphs. (Think of a
    file directory tree).

    Inside a template that matches paragraphs ( <xsl:template
    match="paragraph"> ) I need to be able to say: position of current
    paragraph is (for example) /1/3/5/2

    Like the command 'pwd' in Linux, but with positions instead of
    directory names.
    ( /#7/#4/#5 instead of /usr/lib/java )

    But I am also very thankful for a proposed solution with names,
    instead of numbers!!!

    Thanx in advice!
     
    Ivan_G_S, Jan 22, 2008
    #1
    1. Advertising

  2. Ivan_G_S wrote:

    > Inside a template that matches paragraphs ( <xsl:template
    > match="paragraph"> ) I need to be able to say: position of current
    > paragraph is (for example) /1/3/5/2
    >
    > Like the command 'pwd' in Linux, but with positions instead of
    > directory names.
    > ( /#7/#4/#5 instead of /usr/lib/java )


    Do you want the position based on all nodes (use
    count(preceding-sibling::node()) or an all elements (use
    count(preceding-sibling::*) or on the elements of the same name (use
    count(preceding-sibling::paragraph)? For the complete path you need to
    walk the ancestor axis.


    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Jan 22, 2008
    #2
    1. Advertising

  3. Ivan_G_S

    Ivan_G_S Guest

    Thank you!
    But how can I walk the ancestor axis?
    I have tried a recursive named template, but I don't know how to call
    a template with the parent as new context.

    what i need is a naming like:

    root (path: 1)
    - node (path: 1/1)
    - node (path: 1/2)
    - - node (path: 1/2/1)
    - - node (path: 1/2/2)
    - node (path: 1/3)
    - - node (path: 1/3/1)
    - - node (path: 1/3/2)
    - - - node (path: 1/3/1/1)

    so, every path name is: "the path of parent" + '/' + "number among
    siblings"

    On Jan 22, 5:02 pm, Martin Honnen <> wrote:

    > Do you want the position based on all nodes (use
    > count(preceding-sibling::node()) or an all elements (use
    > count(preceding-sibling::*) or on the elements of the same name (use
    > count(preceding-sibling::paragraph)? For the complete path you need to
    > walk the ancestor axis.
    >
    > --
    >
    >         Martin Honnen
    >        http://JavaScript.FAQTs.com/
     
    Ivan_G_S, Jan 22, 2008
    #3
  4. Ivan_G_S wrote:

    > But how can I walk the ancestor axis?


    <xsl:for-each select="ancestor::*">
    for instance to look at all ancestor elements.


    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Jan 22, 2008
    #4
  5. In article <>,
    Ivan_G_S <> wrote:

    >I'm looking for a possibility to create a kind of URL, which
    >represents the absolute path to a node.
    >
    >I have an XML document with multiple-nested paragraphs. (Think of a
    >file directory tree).
    >
    >Inside a template that matches paragraphs ( <xsl:template
    >match="paragraph"> ) I need to be able to say: position of current
    >paragraph is (for example) /1/3/5/2


    There is a standard syntax of just this kind, usable as a fragment
    identifier in URIs for XML documents:

    http://www.w3.org/TR/xptr-element/

    -- Richard
    --
    :wq
     
    Richard Tobin, Jan 22, 2008
    #5
  6. See part 2 of my "styling stylesheets" article on DeveloperWorks
    (http://www.ibm.com/xml); it includes a template which will generate a
    PseudoXPath to a node. (I realized after publication that producing a
    real, but slightly ugly XPath isn't that much harder if you use
    predicates, but the editors didn't seem to have a way for me to go back
    and tack that tip onto the article. Oh well.)

    I suspect that XPath is a better solution for your needs... but at the
    very least this will show you how to do the recursive counting needed to
    build up your version.

    --
    Joe Kesselman / Beware the fury of a patient man. -- John Dryden
     
    Joseph Kesselman, Jan 22, 2008
    #6
    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. Replies:
    0
    Views:
    1,470
  2. Ralf Wahner
    Replies:
    2
    Views:
    2,414
    Ralf Wahner
    Jul 15, 2003
  3. Tjerk Wolterink
    Replies:
    2
    Views:
    1,440
    Dimitre Novatchev
    Aug 24, 2006
  4. Replies:
    3
    Views:
    3,849
    A. Bolmarcich
    Oct 20, 2006
  5. Knut Krueger
    Replies:
    2
    Views:
    447
    Knut Krueger
    May 21, 2007
Loading...

Share This Page