Re: [xsl] Formatting issues

Subject: Re: [xsl] Formatting issues
From: ms <mina_hurray@xxxxxxxxx>
Date: Fri, 22 Dec 2006 13:35:54 -0800 (PST)
Hi Abel:

Thank you for your response.

Actually, there can be 6 levels in my document. Each
level is formatted differencetly.

Level1 - 1,2,3 etc
Level2 - A, B, C
Level3 - i,ii,..
Level4 - (1), (2)
Level5 - (a), (b)
Level6 - (i), (ii)

The hierarchy for levels is that level 1 is the parent
for level2, level2 is he parent for level3 and so on.
i.e.

<level1>
     <level2>
        <level3>
           <level4>
              <level5>
                 <level6>
                  </level6>
              </level5>
           </level4>
        </level3>
      </level2>
</level1>

Now in an XML , there can be any number of these
levels, and I have a logic to filter these levels
based on certain conditions.

So suppose I have an XML like this:

<level1>
---something here--
</level1>

</level1>
--somehting else here--
</level1>

<level1>
-- --
</level1>

So accodring to the formatting, the output for these
levels would have numbers 1, 2 ,3. But suppose the
first level1 and second level1 were filtered, then the
third level1 should start with number 1. and not
number 3.

I tried <xsl:number from="level1" format="1"/>
But that only numbers all levels with 1 and does not
increment them sequentially. 

This is my problem. How do I write the XSLT to
basically check if previous levels have satisfied the
filtering condition and if they have, include them for
counting, else remove them and count only those levels
that satisfy the condition and count sequentially.

Thanks









--- Abel Braaksma <abel.online@xxxxxxxxx> wrote:

> Hi ms,
> 
> I'm not sure I understand you. What is a level? Is
> that 1.1.1, 1.1.2 
> etc, as in legal documents? Or do you mean something
> like with chapters? 
> Are the levels leveled in your document
> hierarchically, ie:
> <level1><level2><level3/></level2></level1> ?
> 
> Do you really mean to match a part of the nodename?
> What actually is the 
> problem with your current XSLT file? You talk of
> formatting, do you 
> perhaps mean xsl-fo? If about XSLT, what version?
> 
> Please answer the above in a subsequent post if I am
> on the wrong track 
> here.
> 
> The following self-contained XSLT 2.0 stylesheet
> takes your input, 
> indents it depending on the real level (independent
> of your re-count 
> request) and starts numbering anew when not at the
> right spot.
> 
> Note that I employ the <xsl:next-match /> here to
> make life a little 
> easier. If you cannot use XSLT 2.0, you'll have to
> add a few constructs 
> to achieve the same goal, but the idea remains the
> same. The output of 
> the below stylesheet is as follows (note the
> indentation and the 
> numbering) (for input see variable $levels):
> 
> At level 1, number: 1
>    At level 2, number: 1
>    At level 2, number: 2
>    At level 2, number: 3
>    At level 2, number: 4
>                At level 5, number: 1
>                At level 5, number: 2
>        At level 3, number: 1
>        At level 3, number: 2
>        At level 3, number: 3
> 
> 
> 
> The stylesheet:
> 
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <xsl:stylesheet
>     xmlns:xs = "http://www.w3.org/2001/XMLSchema";
>     xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
> version="2.0">
>    
>     <xsl:output indent="yes" />
>    
>     <xsl:variable name="levels">
>         <level1>
>             <level2 />
>             <level2 />
>             <level2 />
>             <level2 />
>             <level5 />  <!-- assuming this oddity is
> what you mean -->
>             <level5 />  <!-- assuming this oddity is
> what you mean -->
>         </level1>
>         <level3 />  <!-- assuming this oddity is
> what you mean -->
>         <level3 /> 
>         <level3 /> 
>     </xsl:variable>
>    
>     <xsl:template match="/">
>         <xsl:apply-templates select="$levels//*" />
>     </xsl:template>
>    
>     <!-- catch-all for the textual part -->
>     <xsl:template match="*" priority="5">
>         <xsl:text>
</xsl:text>
>         <xsl:value-of select="
>             for $i in
>                 1 to xs:integer(substring(name(), 6,
> 1)) - 1
>               return '   '" />
>         <xsl:text>At level </xsl:text>
>        
>         <xsl:value-of
> select="concat(substring(name(), 6, 1), ', number: 
> ')" />
>        
>         <!-- apply again -->
>         <xsl:next-match />
>     </xsl:template>
>    
>     <!-- wrong level, no correct parent -->
>     <xsl:template match="*" priority="0">
>         <xsl:variable
> name="number"><xsl:number/></xsl:variable>
>         <xsl:value-of select="$number" />
>     </xsl:template>
>    
>     <!-- correct level, with parent of one lower
> level -->
>     <xsl:template match="
>         *[parent::*[
>             number(substring(name(), 6, 1))
>             = number(substring(current()/name(), 6,
> 1)) - 1]
>          ]">
>         <xsl:variable
> name="number"><xsl:number/></xsl:variable>
>         <xsl:value-of select="$number" />
>     </xsl:template>
> </xsl:stylesheet>
> 
> 
> HtH, Cheers,
> 
> -- Abel
>    http://www.nuntia.nl
> 
> 
> ms wrote:
> > Hello:
> >
> > I have issues with formatting. 
> >
> > In my XML file, I have an element called <level>
> and
> > there can be 6 levels. 
> >
> > <level1>...<level6>
> >
> > I am applying a filtering logic for all levels.
> >
> > So suppose I have an XML like this:
> >
> > <level1>
> > .........
> > </level1>
> >
> > <level1>
> > .....
> > </level1>
> >
> >
> > <level1>
> > ...
> > </level1>
> >
> > The output will be 
> > 1.
> > 2.
> > 3.
> >
> > Now based on the filtering logic, if level1 and 2
> are
> > eliminated, then level 3 should start with number
> 1.
> > and not with number 3. 
> >
> > Is there a way to deal with this? Thanks in
> advance
> > for your help. 
> >
> >
> > __________________________________________________
> > Do You Yahoo!?
> > Tired of spam?  Yahoo! Mail has the best spam
> protection around 
> > http://mail.yahoo.com 
> 
=== message truncated ===


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

Current Thread