|
||||||||
| Chapter 4 - Templates Rule! | |
| XSLT For Dummies | |
| by Richard Wagner | |
| Hungry Minds 2002 | |
Working with Named Templates
A
named template
is an
xsl:template
element that has a
To
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template name="CreditLine"> <xsl:value-of select="."/> - Brought to you by Tumplates, The Template People. </xsl:template> <xsl:template match="film"> Film: <xsl:call-template name="CreditLine"/> </xsl:template> <xsl:template match="composer"> Composer: <xsl:call-template name="CreditLine"/> </xsl:template> <xsl:template match="year"/> <xsl:template match="grade"/> </xsl:stylesheet> The first xsl:template element is the named template. When called, it adds text to the result document using xsl:value-of . However, without a match attribute defined, the XSLT processor has nothing to evaluate so the processor ignores the named template unless its explicitly called somewhere else.
The
Film: A Little Princess - Brought to you by Tumplates, The Template People. Composer: Patrick Doyle - Brought to you by Tumplates, The Template People. Tip To find out how to use named templates in combination with parameters, see Chapter 8.
|
|||||||||||
|
||||||||
| Chapter 5 - XPath Espresso | |
| XSLT For Dummies | |
| by Richard Wagner | |
| Hungry Minds 2002 | |
Chapter 5: XPath Espresso
In This ChapterMy guess is that XPath is the espresso drinker of the X-Team. Its the high-energy workman that tirelessly treads through XML documents all hours of the day and night looking for those pesky nodes. Geez, with all that effort, it needs a good shot of espresso just to keep going! Besides, XPath has another tie-in with coffee: Creating XPath expressions reminds me of ordering a drink at Starbucks. XPath is the one X-Teamer built from the ground up to decipher confusing instructions like: Id like a venti, triple shot, wet cappuccino with nonfat milk and a dash of cinnamon. This process of taking a specific request and going in and returning the right set of nodes (or cappuccinos) is what XPath is all about.
|
|||||||||||