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

RE: Newbie issue with apply-templates and output

Subject: RE: Newbie issue with apply-templates and output
From: "Majirus FANSI" <jmfansi@xxxxxxxxxxx>
Date: Fri, 11 Mar 2005 17:46:36 +0100
template in output xml
<xsl:template match="element">
  <temp><xsl:value-of select="."/></temp>
  <xsl:apply-templates/>
</xsl:template>

according to this template, for every "element" node, the processor will produce and <temp> node which content is resume by ".//text()". That is "heading1" for example in your case. After this, it (the processor) will call all descendant node of "element" and then apply a defaut template to those for which there is no template defined. That's why "heading1" appears after <temp> node.
you can read "XSLT programer's reference, wrox press isbn: 1-861005-06-7" for more information about default processing.
change <xsl:apply-template/> to <xsl:apply-template select="*"/> for precluding appearance of "heading x" text node.


Hope this help
regards

From: "A.Little" <A.Little@xxxxxxxxxx>
Reply-To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
To: xsl-list <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Subject:  Newbie issue with apply-templates and output
Date: Fri, 11 Mar 2005 16:21:36 -0000

Hi,

I'm quite new to all this XSL stuff and have now got very confused with
what's happening with the output using my XSL - it's dumping out the
text from nodes even tough I've not specified in the XSL to do this. The
code (xml & xsl) is given below with the output - and I'm confused why
it's output 'heading 1' etc twice, and why 'I'm here' is being output at
all. How can I change my xsl so it only outputs the headings once, and
the extra text isn't displayed at all?

It's probably obvious to everyone else - but not to me! :-(

Any help/explanation much appreciated,
Alex
 --------------------
Here's the XSL:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml"/>

<xsl:template match="/">
	<report>
	<xsl:apply-templates/>
	</report>
</xsl:template>

<xsl:template match="element">
  <temp><xsl:value-of select="."/></temp>
  <xsl:apply-templates/>
</xsl:template>

<xsl:template match="body">
 <xsl:apply-templates/>
</xsl:template>

</xsl:stylesheet>

And here is the xml:

<?xml version="1.0" encoding="UTF-8"?>
<html>
	<element>heading 1</element>
	<element>heading 2</element>
	<body>
		<element>heading 3</element>
		<element>heading 4</element>
		I'm here
	</body>
</html>

But the output I'm getting is:

<?xml version="1.0" encoding="UTF-16"?>
<report>
	<temp>heading 1</temp>
	heading 1
	<temp>heading 2</temp>
	heading 2
	<temp>heading 3</temp>
	heading 3
	<temp>heading 4</temp>
	heading 4
	I'm here
</report>


_________________________________________________________________
MSN Messenger : dialoguez en temps riel avec vos amis ! http://g.msn.fr/FR1001/866


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.