[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

XSLT Position of Ancestor

Posted on 2005-05-03
3
Medium Priority
?
3,294 Views
Last Modified: 2009-07-29
Hello
I need to get the position of the ancestor when i am in a grand-child.
Say i am in <item2> within the <submenu>
I need to go a find the position of its <item1>
How do i do this?

<themenu>
      <item>
            <title>Home</title>
            <link>www.xtra.co.nz</link>
      </item>
      <item1>
            <title>Joana</title>
            <link>www.xtra.co.nz</link>
      </item1>
      <item1>
            <title>Craig</title>
            <link>www.xtra.co.nz</link>
      </item>
      <item1>
            <title subNo="Yes">Jim</title>
            <link>www.xtra.co.nz</link>
            <submenu>
                  <item2>
                        <title>Mic</title>
                        <link>www.xtra.co.nz</link>
                  </item2>
                  <item2>
                        <title>Grant</title>
                        <link>www.xtra.co.nz</link>
                  </item2>
                  <item2>
                        <title>Dave</title>
                        <link>www.xtra.co.nz</link>
                  </item2>
            </submenu>
      </item1>

<themenu>
0
Comment
Question by:Joana
3 Comments
 
LVL 15

Accepted Solution

by:
dualsoul earned 500 total points
ID: 13925548
hm...do you mean count item1, if you are in context of item2?

you can do it for instance this way: count(ancestor::item1/preceding-sibling::item1)

check this XSLT:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      <xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes"/>
      
      <xsl:template match="/">
            <xsl:for-each select="//item2">
                  Item2=<xsl:value-of select="." /><br/>
                  Ancestor Position is <xsl:value-of select="count(ancestor::item1/preceding-sibling::item1)" />
            </xsl:for-each>
      </xsl:template>
</xsl:stylesheet>
0
 

Expert Comment

by:uwebe
ID: 13929532
well done dualsoul

Gasper
0
 

Author Comment

by:Joana
ID: 14105716
Sorry for taking so long, forgot i hadn't changed my email address fo new job.  Thanks heaps for the answer it was just what i was looking for.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Loops Section Overview

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question