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

Re: Apply Templates, when to use which? how do templat

Subject: Re: Apply Templates, when to use which? how do templates work?
From: "Andrew Welch" <andrew.j.welch@xxxxxxxxx>
Date: Tue, 28 Aug 2007 12:42:30 +0100
Re:  Apply Templates
On 8/28/07, John Smith <debrief@xxxxxxxxx> wrote:
> The concept of templates is confusing me a bit as I am used to think
> of functions like imperative programming languages. So...

Just to add to Davids response, a good way to understand templates and
the way XSLT works is think about the following stylesheet:

<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" />

This is a stylesheet with no templates at all - it's an empty element.

If you run a transform using that stylesheet with this input:

<root example="input">
	<node>Hello</node>
	<node>World</node>
</root>

...you get this output:

<?xml version="1.0" encoding="UTF-8"?>
	Hello
	World

This is because of the default template rules.  Understand these and
soon after you'll "get" templates.  Note the indentation, and that the
attribute is ignored.

Try running the examples, and then add the root matching template:

<xsl:template match="/">
  abc
</xsl:template>

Work out why the output is now:

<?xml version="1.0" encoding="UTF-8"?>
 abc

Then to answer most of the questions in your original post, try to get
the attribute "example" to come out, or make "Hello World" appear all
on one line.

cheers
andrew
-- 
http://andrewjwelch.com

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-2011 All Rights Reserved.