XML Tutorial/XSLT stylesheet/attribute set — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Текущая версия на 11:26, 26 мая 2010
Содержание
- 1 Several attributes can be grouped together and then used at once with xsl:attribute-set and xsl:use-attribute-sets
- 2 <xsl:value-of select="."/>
- 3 GREETING
- 4 <xsl:value-of select="title"/>
- 5 Here"s the same table with different attribute sets:
- 6 title 1
- 7 Here"s the same table with different attribute sets:
Several attributes can be grouped together and then used at once with xsl:attribute-set and xsl:use-attribute-sets
<source lang="xml">
File: Data.xml <?xml version="1.0" encoding="utf-8"?>
<TITLE>GREETING</TITLE> <TEXT>Hello, world!</TEXT>
File: Transform.xslt <?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet
version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match=" TITLE">
<xsl:value-of select="."/>
</xsl:template> <xsl:template match=" TEXT">
<xsl:value-of select="."/>
</xsl:template> <xsl:attribute-set name="titleStyle"> <xsl:attribute name="align">center</xsl:attribute> <xsl:attribute name="style">color:red</xsl:attribute> </xsl:attribute-set> <xsl:attribute-set name="textStyle"> <xsl:attribute name="align">right</xsl:attribute> <xsl:attribute name="style">color:blue</xsl:attribute> </xsl:attribute-set>
</xsl:stylesheet> Output: <?xml version="1.0" encoding="UTF-8"?>
GREETING
Hello, world!
</source>
table with different attribute sets
<source lang="xml">
File: Data.xml <?xml version="1.0"?>
<list xml:lang="en">
<title>title 1</title> <listitem>item 1</listitem> <listitem>item 2</listitem> <listitem>item 3</listitem> <listitem xml:lang="sw">item 4</listitem> <listitem xml:lang="en-gb">item 5</listitem> <listitem xml:lang="zu">item 6</listitem> <listitem xml:lang="jz">item 7</listitem>
</list>
File: Transform.xslt <?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="html"/> <xsl:attribute-set name="bold-table"> <xsl:attribute name="style"> font-weight: bold; </xsl:attribute> </xsl:attribute-set> <xsl:attribute-set name="spacious-table" use-attribute-sets="bold-table"> <xsl:attribute name="cellpadding">8</xsl:attribute> <xsl:attribute name="cellspacing">8</xsl:attribute> </xsl:attribute-set> <xsl:attribute-set name="reverse-table"> <xsl:attribute name="bgcolor">black</xsl:attribute> <xsl:attribute name="style">color: white;</xsl:attribute> </xsl:attribute-set> <xsl:template match="/"> <html> <head> <title><xsl:value-of select="/list/title"/></title> </head> <body style="font-family: sans-serif;"> <xsl:apply-templates select="*"/> </body> </html> </xsl:template> <xsl:template match="list">
<xsl:value-of select="title"/>
<xsl:value-of select="."/> |
Here"s the same table with different attribute sets:
<xsl:value-of select="."/> |
</xsl:template>
</xsl:stylesheet> Output: <html>
<head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>title 1</title> </head> <body style="font-family: sans-serif;">
title 1
item 1 |
item 2 |
item 3 |
item 4 |
item 5 |
item 6 |
item 7 |
Here"s the same table with different attribute sets:
item 1 |
item 2 |
item 3 |
item 4 |
item 5 |
item 6 |
item 7 |
</body>
</html></source>