[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

AW: counting again

Subject: AW: counting again
From: Michael Schäfer <MSchaefer@xxxxxxxxxxxx>
Date: Thu, 12 Jul 2001 15:44:02 +0200
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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.