关于XSLT中的模板问题
xml文件: books.xml
<?xml version='1.0'?><?xml-stylesheet type="text/xsl" href="Books_apply_templates.xsl"?><!-- This file represents a fragment of a book store inventory database --><bookstore> <book genre="autobiography"> <title>The Autobiography of Benjamin Franklin</title> <author> <first-name>Benjamin</first-name> <last-name>Franklin</last-name> </author> <price>8.99</price> </book> <book genre="novel"> <title>The Confidence Man</title> <author> <first-name>Herman</first-name> <last-name>Melville</last-name> </author> <price>11.99</price> </book> <book genre="philosophy"> <title>The Gorgias</title> <author> <name>Plato</name> </author> <price>9.99</price> </book></bookstore>
<?xml version="1.0"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="html" /> <xsl:template match="/"> <html> <body> <h2>My Book Collection</h2> <xsl:apply-templates /> </body> </html> </xsl:template> <xsl:template match="book"> <p> <xsl:apply-templates select="title"/> <xsl:apply-templates select="price"/> </p> </xsl:template> <xsl:template match="title"> Title: <span style="color:#ff0000"> <xsl:value-of select="."/> </span> <br /> </xsl:template> <xsl:template match="price"> Artist: <span style="color:#00ff00"> <xsl:value-of select="."/> </span> <br /> </xsl:template></xsl:stylesheet>
<body> <h2>My Book Collection</h2> <xsl:apply-templates /> </body>
<xsl:apply-templates />
<xsl:apply-templates select="book"/>
<xsl:apply-templates select="bookstore/book"/>