This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: can I give xsl:number a starting position?
- From: "Jeff Rosler" <jeff dot rosler at flatironssolutions dot com>
- To: <xsl-list at lists dot mulberrytech dot com>
- Date: Wed, 4 Sep 2002 17:15:40 -0600
- Subject: RE: [xsl] can I give xsl:number a starting position?
- Reply-to: xsl-list at lists dot mulberrytech dot com
I have java code that knows the root number for each of the chunks.
Within the java code, I do a transform on each chunk and pass the root
number into the stylesheet. The root number is chunked to an h3 level
and is broken up into "chapter.h1.h2.h3.h4" where the format is
1.1.A.1.A. I used Michael's suggestion and wrote a template to get these
section numbers. The XSL looks something like this.
<!-- params at the top of the stylesheet -->
<xsl:param name="start-chapter" select="1" />
<xsl:param name="start-h1" select="1" />
<xsl:param name="start-h2" select="1" />
<xsl:param name="start-h3" select="1" />
...
<!--
call the template to output the section number with the chapter
title
-->
<xsl:template match="chapter/title">
<div class="chapter">
<xsl:call-template name="GetSectionNumber">
<xsl:with-param name="string" select="name(..)" />
</xsl:call-template>
<xsl:text> </xsl:text>
<xsl:apply-templates />
</div>
</xsl:template>
...
<!--
Get the section number for a particular section
(chapter,h1,h2,h3,h4, etc.) from the linkbase
-->
<xsl:template name="GetSectionNumber">
<xsl:param name="string" />
<xsl:number
value="count(ancestor::chapter/preceding-sibling::chapter)+$start-chapte
r" format="1"/>
<xsl:text>.</xsl:text>
<xsl:choose>
<xsl:when test="contains($string,'h1')">
<xsl:number
value="count(ancestor::h1/preceding-sibling::h1)+$start-h1" format="1"/>
<xsl:text>.</xsl:text>
</xsl:when>
<xsl:otherwise><xsl:choose>
<xsl:when test="contains($string,'h2')">
<xsl:number
value="count(ancestor::h1/preceding-sibling::h1)+$start-h1" format="1"/>
<xsl:text>.</xsl:text>
<xsl:number
value="count(ancestor::h2/preceding-sibling::h2)+$start-h2" format="A"/>
<xsl:text>.</xsl:text>
</xsl:when>
<xsl:otherwise><xsl:choose>
<xsl:when test="contains($string,'h3')">
<xsl:number
value="count(ancestor::h1/preceding-sibling::h1)+$start-h1" format="1"/>
<xsl:text>.</xsl:text>
<xsl:number
value="count(ancestor::h2/preceding-sibling::h2)+$start-h2" format="A"/>
<xsl:text>.</xsl:text>
<xsl:number
value="count(ancestor::h3/preceding-sibling::h3)+$start-h3" format="1"/>
<xsl:text>.</xsl:text>
</xsl:when>
<xsl:otherwise><xsl:choose>
<xsl:when test="contains($string,'h4')">
<xsl:number
value="count(ancestor::h1/preceding-sibling::h1)+$start-h1" format="1"/>
<xsl:text>.</xsl:text>
<xsl:number
value="count(ancestor::h2/preceding-sibling::h2)+$start-h2" format="A"/>
<xsl:text>.</xsl:text>
<xsl:number
value="count(ancestor::h3/preceding-sibling::h3)+$start-h3" format="1"/>
<xsl:text>.</xsl:text>
<xsl:number
value="count(preceding-sibling::h4)+number('1')" format="A"/>
<xsl:text>.</xsl:text>
</xsl:when>
</xsl:choose></xsl:otherwise>
</xsl:choose></xsl:otherwise>
</xsl:choose></xsl:otherwise>
</xsl:choose>
</xsl:template>
-----Original Message-----
From: owner-xsl-list@lists.mulberrytech.com
[mailto:owner-xsl-list@lists.mulberrytech.com] On Behalf Of Wendell Piez
Sent: Wednesday, September 04, 2002 12:01 PM
To: xsl-list@lists.mulberrytech.com
Subject: RE: [xsl] can I give xsl:number a starting position?
Jeff,
At 04:33 AM 9/4/2002, you wrote:
> > Basically, my problem is that I have an XML document that's been
> > chunked up into smaller pieces. I need to convert each of those
> > pieces to HTML separately, with the correct section numbers.
Since you're starting with files that have already been chunked, you
can't
effectively use xsl:number to get your numbers, so you have to manage it
some other way. (Neither will position() or counting certain kinds of
ancestors be much use, since the document being transformed is not the
"document" the numbering needs to be in reference to.)
An alternative, if this is thinkable, is to run the transform over the
unchunked document, parameterizing which chunk is to be processed for
each
run. Since the entire document is available to the transform, the
numbering
can be in reference to the whole.
An alternative, if your chunking routine is also XSLT (or sometimes even
if
not) is to provide the numbering in that transformation, and then just
pass
it through the second step.
Cheers,
Wendell
======================================================================
Wendell Piez mailto:wapiez@mulberrytech.com
Mulberry Technologies, Inc. http://www.mulberrytech.com
17 West Jefferson Street Direct Phone: 301/315-9635
Suite 207 Phone: 301/315-9631
Rockville, MD 20850 Fax: 301/315-8285
----------------------------------------------------------------------
Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list