XSLT 4-1
XSLT XML XML HTML XSLT 1.0 (W3C ) http://www.w3.org/tr/xslt http://www.zvon.org/xxl/xsltreference/output/ ( ) XML 4-2
XSLT XML <?xml version="1.0" encoding="shift_jis"?> <booklist> <book id="kobe:xml"> <title>xml </title> <author> </author> <author> </author> <publisher> </publisher> <price unit="yen">2000</price> </book> <book id="hyogo:java"> <title>java </title> <author> </author> <publisher> </publisher> <price unit="yen">1500</price> <image ref="java_nymon.jpg"/> </book> </booklist> 4-3
XSLT ( ) <?xml version="1.0" encoding="shift_jis"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/xsl/transform" version="1.0"> <xsl:output method="html" encoding="shift_jis"/> <xsl:strip-space elements="*"/> <xsl:template match="/booklist"> <html> <body> <table border="1"> <tr><th> </th><th> </th><th> </th></tr> <xsl:apply-templates/> <tr><td colspan="2" align="center"> </td> <td align="right"><xsl:value-of select="sum(book/price)"/></td></tr> </table> </body> </html> <xsl:template match="book"> <tr><td><xsl:value-of select="title"/></td> <td><xsl:value-of select="author"/></td> <td align="right"><xsl:value-of select="price"/></td></tr> </xsl:stylesheet> 4-4
xsl:output method xml, html, text encoding xsl:strip-space elements ( XML ) xsl:preserve-space 4-5
( ) xsl:template match xsl:apply-template select (XPath ) select xsl:value-of XPath select 4-6
(expression) XPath : <xsl:apply-templates select=" "> : <xsl:if test=" "> : <xsl:value-of select=" "> : <element attr="{ }"> 4-7
(pattern) (pattern): 1 (location path pattern): XPath child attribute // id( ) ID key(, ) xsl:key XPath 4-8
<xsl:template match=" "> xsl:apply-templates <xsl:template name=" "> xsl:call-template XSLT 4-9
<!-- : --> <xsl:template match="/ *"> <xsl:apply-templates/> <!-- : --> <xsl:template match="text() @*"> <xsl:value-of select="."/> <!-- : --> <xsl:template match="processing-instruction()"/> <!-- : --> <xsl:template match="comment()"/> 4-10
priority 0.5 : match="text()" *, @* 0.25 0 : match="book", match="@id" 0.5 : match="book/author" 4-11
<xsl:apply-templates select=" "/> select ( ) <!-- --> <xsl:apply-templates/> <!-- --> <xsl:apply-templates select="*"/> <!-- author --> <xsl:apply-templates select="author"/> <!-- author --> <xsl:apply-templates select=".//author"/> 4-12
( ) xsl:apply-templates xsl:apply-templates apply(current_node, current_node_list) = find matching rules for the current_node; choose the highest priority rule in the matching rules; foreach apply-templates instruction in the rule { node_list = nodeset sepecified by select; foreach node in node_list { apply(node, node_list); } } 4-13
( ) ( 1 ) XPath XPath 4-14
<!-- book image --> <xsl:template match="book/image"> <xsl:value-of select="@ref"/> <!-- book image --> <xsl:template match="book[image]"> <xsl:value-of select="image/@ref"/> <!-- author --> <xsl:template match="/"> <xsl:apply-templates select=".//author"/> 4-15
<xsl:call-templates name=" "/> 4-16
xsl:value-of : : <xsl:value-of select="@ref"/> : <xsl:value-of select="position()"/> xsl:element : xsl:attribute : xsl:text : ( ) xsl:processing-instruction : xsl:comment : xsl:copy-of : xsl:copy : ( ) 4-17
( ) xsl:number : <xsl:template match="/booklist">... <td align="right"> <xsl:number value="sum(book/price)" grouping-separator="," grouping-size="3"/> </td>... <xsl:template match="book">... <td align="right"> <xsl:number count="book"/> </td>... 4-18
if <xsl:for-each select=" "> </xsl:for-each> <xsl:if test=" "> </xsl:if> <xsl:choose> <xsl:when test=" 1"> 1</xsl:when> <xsl:when test=" 2"> 2</xsl:when>... <xsl:otherwise> </xsl:otherwise> </xsl:choose> 4-19
<xsl:template match="/booklist">... <!-- xsl:apply-templates --> <xsl:apply-templates select="book"> <xsl:sort select="price" data-type="number"/> </xsl:apply-templates>... <xsl:template match="/booklist">... <!-- xsl:for-each --> <xsl:for-each select="book"> <xsl:sort select="price" data-type="number"/>... </xsl:for-each>... 4-20
xsl:variable : ( ) <xsl:variable name=" " select=" "/> <!-- --> <xsl:variable name=" "> </xsl:variable> xsl:param : <xsl:param name=" " select=" "/> <xsl:param name=" "> </xsl:param> xsl:param xsl:template xsl:apply-templates, xsl:call-template xsl:with-param 4-21
xsl:include href xsl:import href xsl:apply-imports 4-22
XML <?xml version="1.0" encoding="shift_jis"?> <?xml-stylesheet href="style1.xsl" type="text/xsl"?> <booklist> <book id="kobe:xml"> <title>xml </title> <author> </author> <author> </author> <publisher> </publisher> <price unit="yen">2000</price> </book> <book id="hyogo:java"> <title>java </title> <author> </author> <publisher> </publisher> <price unit="yen">1500</price> <image ref="java_nymon.jpg"/> </book> </booklist> 4-23
XSLT.java XML XML XML Web 4-24