xsl-list
[Top] [All Lists]

Re: [xsl] Apply Templates, when to use which? how do templates work?

2007-08-28 04:43:35
On 8/28/07, John Smith <debrief(_at_)gmail(_dot_)com> 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

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--