[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] AW: counting again
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@xxxxxxxxxxxxxxxxxxxxxx [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx]Im Auftrag von Michael Schäfer Gesendet: Donnerstag, 12. Juli 2001 14:29 An: XSL-Liste (E-Mail) Betreff: 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@xxxxxxxxxxxx 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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|