xsl-list
[Top] [All Lists]

RE: [xsl] Count Ancestors Up To But Not Including a Given Type

2008-02-05 02:52:45

Perhaps

<xsl:for-each-group select="reverse(ancestor::*[self::ol|self::ul])"
group-adjacent="node-name()">
  <xsl:if test="position()=1">
    <xsl:sequence select="count(current-group())"/>
  </xsl:if>
</xsl:for-each-group>

That is, partition the ancestors into runs of ol or ul, and then get the
length of the first run.

Michael Kay
http://www.saxonica.com/

-----Original Message-----
From: Eliot Kimber [mailto:ekimber(_at_)reallysi(_dot_)com] 
Sent: 05 February 2008 07:18
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] Count Ancestors Up To But Not Including a Given Type

Maybe it's the lateness of the hour but I'm finding myself 
stymied on what I hope is relatively simple check.

In DITA, as in many doctypes, you can have nested lists of the form:

<ol>
  <li>
   <ol>
    <li>
    </li>
   </ol>
  </li>
</ol>

As well as an intermixing of different list types, e.g.:

<ol>
  <li>
   <ul>
    <li>
     <ol>
      <li>


What I need to do is determine, for a given li, its depth of 
nesting within unbroken ancestry of a given list type.

Thus, int the first example, the deepest li is a level 2 
because it has two ancestor <ol> elements with no intervening 
<ul> (or other non-list element that might occur within <li> 
and itself contain a list). In the second example, the 
deepest <li> is a level one because there is an intervening 
<ul> between the two <ol> ancestors.

I can't for the life of me figure out either a single 
expression or a recursive function that will return the 
correct answer.

What bit of logic am I failing to see? I am using XSLT 2.

Thanks,

ELiot

--
Eliot Kimber
Senior Solutions Architect
"Bringing Strategy, Content, and Technology Together"
Main: 610.631.6770
www.reallysi.com
www.rsuitecms.com

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--