xsl-list
[Top] [All Lists]

RE: Using <xsl:number>

2004-06-09 02:23:36
<xsl:number/> with no attributes should do the job.

The "from" attribute with level="single" is very rarely used, and in the
XSLT 1.0 spec it's very unclear what its intended meaning is.

Michael Kay 

-----Original Message-----
From: David Buddrige [mailto:dbuddrige(_at_)yahoo(_dot_)com] 
Sent: 09 June 2004 04:55
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] Using <xsl:number>

Hi all,

I am trying to figure out how to use the <xsl:number>
tag in the following way:


I have a set of recursively heirarchically structured
tags called "Scopes", in the following xml:


<Data>
      <Scope id="1">
              <Scope id="2"/>
              <Scope id="3"/>
      </Scope>
      <Scope id="4">
              <Scope id="5">
                      <Scope id="6"/>
                      <Scope id="7"/>
              </Scope>
              <Scope id="8">
                      <Scope id="9">
                              <Scope id="10"/>
                              <Scope id="11"/>
                      </Scope>
                      <Scope id="12"/>
              </Scope>
      </Scope>
      <Scope id="13"/>
</Data>

What I want to do is add a sort-order property to each
Scope tag, which identifies its relative position at
each level of the heirarchy among its peers only. 
That is to say, the sort-order tag should be added
like this:

<Data>
      <Scope id="1" sort-order="1">
              <Scope id="2" sort-order="1"/>
              <Scope id="3" sort-order="2"/>
      </Scope>
      <Scope id="4" sort-order="2">
              <Scope id="5" sort-order="1">
                      <Scope id="6" sort-order="1"/>
                      <Scope id="7" sort-order="2"/>
              </Scope>
              <Scope id="8" sort-order="2">
                      <Scope id="9" sort-order="1">
                              <Scope id="10" sort-order="1"/>
                              <Scope id="11" sort-order="2"/>
                      </Scope>
                      <Scope id="12" sort-order="2"/>
              </Scope>
      </Scope>
      <Scope id="13" sort-order="3"/>
</Data>

So that, as you can see, the sort-order is counted at
one level only of the recursive structure.  If there
is a sub-tree coming from a given scope, then the
children are numbered starting at 1 at that direct
decentant level only...

To do this, I have been trying to use the <xsl:number>
tag to insert a new attribute to my xml in the
following way:


<xsl:attribute name=\"sort_order\">";
  <xsl:number level=\"single\" from=\"Scope\"/>";
</xsl:attribute>";

My problem is the "from" attribute... I am reading the
"XSLT Programmers Reference" by  Michael Kay, and the
description for the "from" attribute of the
<xsl:number> tag says that the from field "Determines
a cut-off point, a point in the document from which
sequence numbering starts fresh".

Subsequently, since I want to start numbering fresh
whenever a new subtree begins, I was trying to use
"Scope" as the identifier for the next tag that would
reset numbering...

this does not work however - I always seem to get a
sort-order that is consecutively numbered from the
first element to the last ignoring the recursive
structure of scope tags.

Can anyone help me out with how you go about matching
against any *child* scopes, so that all *child* scopes
reset the numbering, but any sibling scopes are
numbered consecutively?

thanks heaps guys

David.




      
              
__________________________________
Do you Yahoo!?
Friends.  Fun.  Try the all-new Yahoo! Messenger.
http://messenger.yahoo.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>
--+--






<Prev in Thread] Current Thread [Next in Thread>