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

Re: Strange Template Behavior

Subject: Re: Strange Template Behavior
From: Joerg Heinicke <joerg.heinicke@xxxxxx>
Date: Fri, 10 May 2002 01:27:27 +0200
xslo
Because <xsl:value-of select="."/> returns a concatenated string form all descendant text-nodes. What you want is <xsl:value-of select="text()"/>.

Regards,

Joerg

Faroukh Fekravar wrote:
Hi,

I just try to flat the structure of the xml file below:
(I know there are better ways to do that, but I'm interested in knowing why
the approach below does not work)

<?xml version="1.0" encoding="iso-8859-1"?>
<?xml-stylesheet type="text/xsl" href="D:\finder\dims\mm.xsl"?>
<project>
	<aa1>
		<aa11>aa11_value</aa11>
		<aa12>aa12_value</aa12>
		<aa13>aa13_value</aa13>
		<aa2>
			<aa21>aa21_value</aa21>
			<aa22>aa22_value</aa22>
			<aa3>
				<aa31>aa31_value</aa31>
				<aa4>
					<aa41>aa41_value</aa41>
				</aa4>
			</aa3>
		</aa2>
	</aa1>
</project>

by using

<?xml version="1.0" encoding="utf-8"?>
<xslo:stylesheet xmlns:xslo="http://www.w3.org/1999/XSL/Transform"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
	<xslo:output indent="yes"/>
	<xslo:template match="/project">
		<project>
			<xslo:apply-templates/>
		</project>
	</xslo:template>
	<xslo:template match="*"/>
	<xslo:template match='text()'/>
	<xslo:template match="aa1">
		<xslo:element name="aa_1">
			<xslo:apply-templates mode="mapping"/>
		</xslo:element>
			<xslo:apply-templates/>
	</xslo:template>
	<xslo:template match="aa1/aa11" mode="mapping">
		<xslo:element name="aa_11">
			<xslo:value-of select="."/>
		</xslo:element>
	</xslo:template>
	<xslo:template match="aa1/aa12" mode="mapping">
		<xslo:element name="aa_12">
			<xslo:value-of select="."/>
		</xslo:element>
	</xslo:template>
	<xslo:template match="aa1/aa13" mode="mapping">
		<xslo:element name="aa_13">
			<xslo:value-of select="."/>
		</xslo:element>
			<xslo:apply-templates/>
	</xslo:template>
	<xslo:template match="aa2">
		<xslo:element name="aa_2">
		<xslo:apply-templates mode="mapping1"/>
		</xslo:element>
			<xslo:apply-templates/>
	</xslo:template>
	<xslo:template match="aa2/aa21" mode="mapping1">
		<xslo:element name="aa_21">
			<xslo:value-of select="."/>
		</xslo:element>
			<xslo:apply-templates/>
	</xslo:template>
	<xslo:template match="aa3">
		<xslo:element name="aa_3">
		<xslo:apply-templates mode="mapping2"/>
		</xslo:element>
			<xslo:apply-templates/>
	</xslo:template>
	<xslo:template match="aa3/aa31" mode="mapping2">
		<xslo:element name="aa_31">
			<xslo:value-of select="."/>
		</xslo:element>
	</xslo:template>
</xslo:stylesheet>

and I get something like that

<?xml version="1.0" encoding="UTF-16"?>
<project>
	<aa_1>
		<aa_11>aa11_value</aa_11>
		<aa_12>aa12_value</aa_12>
		<aa_13>aa13_value</aa_13>aa21_valueaa22_valueaa31_valueaa41_value</aa_1>
	<aa_2>
		<aa_21>aa21_value</aa_21>aa22_valueaa31_valueaa41_value</aa_2>
	<aa_3>
		<aa_31>aa31_value</aa_31>aa41_value</aa_3>
</project>

Why at the end of each element I have all the values of it's descendants?

It should look like that
<?xml version="1.0" encoding="UTF-16"?>
<project>
	<aa_1>
		<aa_11>aa11_value</aa_11>
		<aa_12>aa12_value</aa_12>
		<aa_13>aa13_value</aa_13>
	</aa_1>
	<aa_2>
		<aa_21>aa21_value</aa_21>
	</aa_2>
	<aa_3>
		<aa_31>aa31_value</aa_31>
	</aa_3>
</project>

I appreciate any help,
Thanks,
Faroukh


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.