This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
AW: counting again
- To: <xsl-list at lists dot mulberrytech dot com>
- Subject: AW: [xsl] counting again
- From: Michael Schäfer <MSchaefer at PFEILGMBH dot DE>
- Date: Thu, 12 Jul 2001 15:44:02 +0200
- Reply-To: xsl-list at lists dot mulberrytech dot com
sorry,
it's clear. I have to use
count(preceding::*[name()=$name])
I hope you hadn't to much trouble.
Michael.
-----Ursprüngliche Nachricht-----
Von: owner-xsl-list@lists.mulberrytech.com
[mailto:owner-xsl-list@lists.mulberrytech.com]Im Auftrag von Michael
Schäfer
Gesendet: Donnerstag, 12. Juli 2001 14:29
An: XSL-Liste (E-Mail)
Betreff: [xsl] counting again
Hello,
I have the following XML-doc
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="test3.xsl"?>
<ROOT>
<TABLE1>
<SUBTABLE>
<EL1>A</EL1>
<EL1>B</EL1>
<EL1>C</EL1>
<EL2>A</EL2>
<EL2>B</EL2>
<EL2>C</EL2>
</SUBTABLE>
</TABLE1>
<TABLE2>
<SUBTABLE>
<EL1>D</EL1>
<EL1>E</EL1>
<EL2>D</EL2>
<EL2>E</EL2>
<EL2>F</EL2>
<EL2>G</EL2>
</SUBTABLE>
</TABLE2>
</ROOT>
I want to add a number to every EL1 and EL2-Element. So I added the
template
<xsl:template match="EL1 | EL2">
<xsl:variable name="name" select="name()"/>
<xsl:copy>
<xsl:element name="{$name}_NR">
<xsl:value-of
select="count(preceding-sibling::*[name()=$name])" />
</xsl:element>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
to the xsl-file.
The result is
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="test3.xsl"?>
<ROOT>
<TABLE1>
<SUBTABLE>
<EL1>
<EL1_NR>0</EL1_NR>A</EL1>
<EL1>
<EL1_NR>1</EL1_NR>B</EL1>
<EL1>
<EL1_NR>2</EL1_NR>C</EL1>
<EL2>
<EL2_NR>0</EL2_NR>A</EL2>
<EL2>
<EL2_NR>1</EL2_NR>B</EL2>
<EL2>
<EL2_NR>2</EL2_NR>C</EL2>
</SUBTABLE>
</TABLE1>
<TABLE2>
<SUBTABLE>
<EL1>
<EL1_NR>0</EL1_NR>D</EL1>
<EL1>
<EL1_NR>1</EL1_NR>E</EL1>
<EL2>
<EL2_NR>0</EL2_NR>D</EL2>
<EL2>
<EL2_NR>1</EL2_NR>E</EL2>
<EL2>
<EL2_NR>2</EL2_NR>F</EL2>
<EL2>
<EL2_NR>3</EL2_NR>G</EL2>
</SUBTABLE>
</TABLE2>
</ROOT>
What I wanted to get is
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="test3.xsl"?>
<ROOT>
<TABLE1>
<SUBTABLE>
<EL1>
<EL1_NR>0</EL1_NR>A</EL1>
<EL1>
<EL1_NR>1</EL1_NR>B</EL1>
<EL1>
<EL1_NR>2</EL1_NR>C</EL1>
<EL2>
<EL2_NR>0</EL2_NR>A</EL2>
<EL2>
<EL2_NR>1</EL2_NR>B</EL2>
<EL2>
<EL2_NR>2</EL2_NR>C</EL2>
</SUBTABLE>
</TABLE1>
<TABLE2>
<SUBTABLE>
<EL1>
<EL1_NR>3</EL1_NR>D</EL1>
<EL1>
<EL1_NR>4</EL1_NR>E</EL1>
<EL2>
<EL2_NR>3</EL2_NR>D</EL2>
<EL2>
<EL2_NR>4</EL2_NR>E</EL2>
<EL2>
<EL2_NR>5</EL2_NR>F</EL2>
<EL2>
<EL2_NR>6</EL2_NR>G</EL2>
</SUBTABLE>
</TABLE2>
</ROOT>
I tried count(//preceding-sibling::*[name()=$name]) but then the result
is 12 every where. Some ideas?
And additionally I want to add a entity to the doc with the last
countings
<COUNTINGS>
<EL1_LNR>5</EL1_LNR>
<EL2_LNR>7</EL2_LNR>
</COUNTINGS>
Mit freundlichen Grüßen
Michael Schäfer
---------------------------------------------------------------
Dipl.-Ing. Michael Schäfer
e-business
Pfeil GmbH
Obertorstr. 4-6
66111 Saarbrücken
Tel.: 06 81/3 79 85-30
Fax: 06 81/3 79 85-13
e-Mail: mschaefer@pfeilgmbh.de
Internet: www.pfeilgmbh.de
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list