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

Re: Formatting issues

Subject: Re: Formatting issues
From: Abel Braaksma <abel.online@xxxxxxxxx>
Date: Fri, 22 Dec 2006 22:15:27 +0100
Re:  Formatting issues
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>&#xA;</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

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.