[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Numbering new nodes using consecutive integers

Subject: Re: Numbering new nodes using consecutive integers
From: Michael Ludwig <mlu@xxxxxxxxxxxxx>
Date: Fri, 27 Mar 2009 18:53:32 +0100
Re:  Numbering new nodes using consecutive integers
David Carlisle schrieb:
you don't need xsl:number here as you're doing all the grouping by
hand so the number you want is I think
      <xsl:attribute name="no">
         <xsl:value-of select="position()+ ceiling(count(../preceding-sibling::G1/M) div $M-per-G2) "/>
       </xsl:attribute>

Thanks. However, this doesn't guarantee unique numbers. By increasing M-per-G2 to 12 and adding some <G1> elements:

    ...
    <M>zwvlf</M>
  </G1>
  <G1><!-- new groups from here -->
    <M>usw</M>
  </G1>
  <G1>
    <M>usw</M>
  </G1>
  <G1>
    <M>usw</M>
  </G1><!-- three new groups -->
</Groups>

And then modifying my template:

  <xsl:template match="M" mode="group">
    <G2><!-- I want this GR to be numbered sequentially. -->
      <xsl:attribute name="no">
        <xsl:number level="any"/>
      </xsl:attribute>
      <xsl:attribute name="david">
        <xsl:value-of select="
          position() +
          ceiling( count(../preceding-sibling::G1/M) div $M-per-G2)"/>
      </xsl:attribute>
      <xsl:copy-of select="
        . | following-sibling::M[position() &lt; $M-per-G2]"/>
    </G2>
  </xsl:template>

I get a wrong result (see below).

There is a certain tedium to the problem. I thought there might be a
standard idiom to sequentially number the result tree. Wendell probably
suggested it: Do it in two passes.

Michael Ludwig

<?xml version="1.0" encoding="iso-8859-1"?>
<Groups>
  <G1>
    <G2 no="1" david="1">
      <M>eins</M>
      <M>zwei</M>
      <M>drei</M>
      <M>vier</M>
      <M>f|nf</M>
      <M>sechs</M>
      <M>sieben</M>
    </G2>
  </G1>
  <G1>
    <G2 no="8" david="2">
      <M>acht</M>
      <M>neun</M>
      <M>zehn</M>
      <M>elf</M>
      <M>zwvlf</M>
    </G2>
  </G1>
  <G1>
    <G2 no="13" david="2">
      <M>usw</M>
    </G2>
  </G1>
  <G1>
    <G2 no="14" david="3">
      <M>usw</M>
    </G2>
  </G1>
  <G1>
    <G2 no="15" david="3">
      <M>usw</M>
    </G2>
  </G1>
</Groups>

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.