This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: 'interleaved' numbering
- From: "Andrew Welch" <awelch at piper-group dot com>
- To: <xsl-list at lists dot mulberrytech dot com>
- Date: Wed, 21 Aug 2002 16:31:42 +0100
- Subject: RE: [xsl] 'interleaved' numbering
- Reply-to: xsl-list at lists dot mulberrytech dot com
Hi,
mmmmm tricky.
First its bad form to post attachments, normally a snippet of data and
what's require is enough :)
Anyway, the problem you have is that <theorem> exist within <subSect>,
therefore <xsl:number> is no good. Also, counting
preceding-sibling::theorem's is no good as you want only those that are
in the current <section>.
So I would recommend creating a variable with the values you need, and
then referencing that variable when you need the number. So as a
top-level-element (child of the root) you would want a variable like:
<xsl:variable name="theorems-rtf">
<xsl:for-each select="//section">
<xsl:for-each select="//theorem">
<theorem id="{generate-id()}" number="{position()}"/>
</xsl:for-each>
</xsl:for-each>
</xsl:variable>
This variable will create a result-tree-fragment that has elements that
look like:
<theorem id="aBcD" number="1"/>
The @number will hold the position of the theorem within each <section>
(therefore the number you want).
So, to perform operations on the r-t-f, you need to convert it to a
node-set:
<xsl:variable name="theorems" select="saxon:node-set($theorems-rtf)"/>
Now whenever you need to generate the number the theorem, you can
generate the first part using <xsl:number> in the normal way, and then
use your nice variable to get the final number:
<xsl:template match="theorem">
<xsl:variable name="id" select="generate-id()"/>
<xsl:value-of select="@name"/>
<xsl:number level="multiple" format="1.1." count="section"/>
<xsl:for-each select="$theorems">
<xsl:value-of select="theorem[@id=$id]/@number"/>
</xsl:for-each>
</xsl:template>
This works by comparing the generated-id() of the current <theorem> with
that held in the variable (generate-id() will always produce that same
result when applied to the same node) to get the @number.
If any of these needs explaining further, please post again.
cheers
andrew
> -----Original Message-----
> From: jody@ifi.unizh.ch [mailto:jody@ifi.unizh.ch]
> Sent: 21 August 2002 15:22
> To: Andrew Welch
> Subject: RE: [xsl] 'interleaved' numbering
>
>
> Hi andrew
> thanks for your reply
> >
> > wayhay, xsl:number my favourite element ;)
> >
> > wont simply leaving out <subsection> from the count
> attribute give you
> > what you need?
> >
> > <xsl:number level="multiple" format="1.1.1"
> > count="block|chapter|section|theorem"/>
> Sorry, this didn't work
>
> Attached to this mail you'll find
> BMMM.xsd Schema for my xml data (probably not needed)
> Test.xml my dummy sample xml file
> BMMM_html.xsl the culprit
>
> Test.xml contains 1 block, 1 chapter and 2 sections
> The first section contains 2 subsections,
> The second section contains 1 subsection.
> There are 2 theorems in the first section, one in each subsection,
> and one theorem in the second section.
>
>
> What i want, is that the theorems in the first section are numbered
> 1.1 and 1.2
> and the theorem in the secon section should be numbered
> 2.1
>
> Currently, they are all numbered 1.1 :(
>
> I have tried all sorts of leaving out bits from the count attribute,
> but none has given me the desired output.
>
> I am using the saxon XSLT processor (http://saxon.sourceforge.net/)
> to transform my xml - do you think that might be the problem?
> Would you suggest that i use an other processor?
>
> Thanks
> jody
>
>
> ---
> Incoming mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.381 / Virus Database: 214 - Release Date: 02/08/2002
>
>
>
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.381 / Virus Database: 214 - Release Date: 02/08/2002
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list