Re: [xsl] Excluding certain nodes from xsl:number count

Subject: Re: [xsl] Excluding certain nodes from xsl:number count
From: George Cristian Bina <george@xxxxxxxxxxxxx>
Date: Thu, 17 May 2007 00:15:29 +0300
Hi Andy,

Then count only Para that do not have Table as ancestor. For instance the following stylesheet should produce something like your expected result:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
<xsl:template match="Table">Then the table...</xsl:template>
<xsl:template match="Para[not(ancestor::Table)]">
<xsl:number from="/Body" level="any" count="Para[not(ancestor::Table)]" format="1."/>
<xsl:value-of select="."/>
</xsl:template>
</xsl:stylesheet>


Best Regards,
George
---------------------------------------------------------------------
George Cristian Bina
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com

Andy Carr1 wrote:
Hi

I have a particular problem trying to exclude certain nodes from being counted.

I am trying to implement paragraph numbering, but some paragraphs (i.e the ones inside tables) should not be numbered and therefore should not be included in the count.

For example, take this snippet of xml:

<Body>

   <Para> Some Text </Para>
   <Para> Some Text </Para>
   <Para> Some Text </Para>
   <Para> Some Text </Para>
   <Para> Some Text </Para>

   <Table>
      <row>
         <cell><Para>Table Text</Para></cell>
         <cell><Para>Table Text</Para></cell>
         <cell><Para>Table Text</Para></cell>
      </row>
   </Table>

   <Para> Some Text </Para>
   <Para> Some Text </Para>
   <Para> Some Text </Para>
   <Para> Some Text </Para>
   <Para> Some Text </Para>

</Body>
This kind of structure needs to be transformed to produce


1. Some Text
2. Some Text
3. Some Text
4. Some Text
5. Some Text

Then the Table...

6. Some Text
7. Some Text
8. Some Text
9. Some Text
10. Some Text

But what I am getting when I use <xsl:number from="Body" level="any" count="Para" format="1." />

1. Some Text
2. Some Text
3. Some Text
4. Some Text
5. Some Text

Then the Table...

9. Some Text
10. Some Text
11. Some Text
12. Some Text
13. Some Text

What I need to do is exclude the Para nodes in the Table from the count, but I can't figure out how.

Anybody?

Regards
Andy

Andy Carr
Senior IT Specialist
Tel: Internal - 298037 External - 01252 558037
Mail Point M1C IBM Application Services
Meudon House, Meudon Avenue, Farnborough, GU14 7NB
(Notes) Andy Carr1/UK/IBM@IBMGB (Internet)CARRA@xxxxxxxxxx







Unless stated otherwise above:
IBM United Kingdom Limited - Registered in England and Wales with number 741598. Registered office: PO Box 41, North Harbour, Portsmouth, Hampshire PO6 3AU

Current Thread