XSLT - 属性をまとめて作成 (xsl:attribute-set)Advertisement書式
<xsl:attribute-set name="名前">
<xsl:attribute name="属性名">属性値</xsl:attribute>
<xsl:attribute name="属性名">属性値</xsl:attribute>
</xsl:attribute-set>
例
<xsl:attribute-set name="typeA">
<xsl:attribute name="src">img01.jpg</xsl:attribute>
<xsl:attribute name="width">300</xsl:attribute>
<xsl:attribute name="height">200</xsl:attribute>
</xsl:attribute-set>
(略)
<img xsl:use-attribute-sets="typeA" />
結果的に以下のコードが生成される。<img src="img01.jpg" width="300" height="200"> サンプルコード
sample.xml
<?xml version="1.0" encoding="Shift_JIS"?>
<?xml-stylesheet type="text/xsl" href="./style.xsl"?>
<book>
<title>XML</title>
<price>1000</price>
</book>
style.xsl
<?xml version="1.0" encoding="Shift_JIS"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:attribute-set name="black6">
<xsl:attribute name="color">black</xsl:attribute>
<xsl:attribute name="size">6</xsl:attribute>
</xsl:attribute-set>
<xsl:attribute-set name="red4">
<xsl:attribute name="color">red</xsl:attribute>
<xsl:attribute name="size">4</xsl:attribute>
</xsl:attribute-set>
<xsl:template match="/">
<html>
<head>
<title>XSLT</title>
</head>
<body>
<xsl:apply-templates select="book"/>
</body>
</html>
</xsl:template>
<xsl:template match="book">
<xsl:value-of select="title"/>
<xsl:value-of select="price"/><br/>
<font xsl:use-attribute-sets="black6">
<xsl:value-of select="title"/>
<xsl:value-of select="price"/><br/>
</font>
<font xsl:use-attribute-sets="red4">
<xsl:value-of select="title"/>
<xsl:value-of select="price"/><br/>
</font>
</xsl:template>
</xsl:stylesheet>
生成されるコード
<html> <head> <title>XSLT</title> </head> <body> XML1000 <font color="black" size="6">XML1000<font> <font color="red" size="4">XML1000<font> </body> </html> Advertisement |
ショートカット・634・634ブログ ・このカテゴリのトップページに戻る ・Incubator(Pukiwiki) ・634ラボ UIコレクションギャラリー ZO-3ジェネレーター サイト検索Y!ログール |