Subject: [xsl] counting again From: Michael Schäfer <MSchaefer@xxxxxxxxxxxx> Date: Thu, 12 Jul 2001 14:28:54 +0200 |
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@xxxxxxxxxxxx Internet: www.pfeilgmbh.de XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Table formatting challeng, DPawson | Thread | Re: [xsl] counting again, Christoph . Oberle |
[xsl] Table formatting challenge, Norman Walsh | Date | Re: [xsl] Table formatting challeng, David Carlisle |
Month |