| Previous | Next
Templates and Template RulesTo control what output is created from what input, you add template rules to the XSLT stylesheet. Each template rule is represented by an The simplest match pattern is an element name. Thus, this template rule says that every time a <xsl:template match="person">A Person</xsl:template> Example 8-4 is a complete stylesheet that uses this template rule. Example 8-4. A very simple XSLT stylesheet<?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="person">A Person</xsl:template> </xsl:stylesheet> Applying this stylesheet to the document in Example 8-1 produces this output: <?xml version="1.0" encoding="utf-8"?> A Person A Person There were two The text "A Person" is called literal data characters, which is a fancy way of saying plain text that is copied from the stylesheet into the output document. A template may also contain literal result elements, i.e., markup that is copied from the stylesheet to the output document. For instance, Example 8-5 wraps the text "A Person" in between Example 8-5. A simple XSLT stylesheet with literal result elements<?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="person"> <p>A Person</p> </xsl:template> </xsl:stylesheet> The output from this stylesheet is: <?xml version="1.0" encoding="utf-8"?> <p>A Person</p> <p>A Person</p> The <xsl:template match="person"> A Person<p> </xsl:template> Here the |