[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
Re: [xsl] Apply Templates, when to use which? how do templates work?
Subject: Re: [xsl] 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 |
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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Apply Templates, when to , G. Ken Holman | Thread | Re: [xsl] Apply Templates, when to , Florent Georges |
Re: [xsl] Apply Templates, when to , G. Ken Holman | Date | Re: [xsl] Apply Templates, when to , John Smith |
Month |
Keywords