要素と属性の生成
【sample010.xml】
<?xml version="1.0" encoding="Shift_JIS" ?>
<?xml-stylesheet href="sample010.xsl" type="text/xsl" ?>
<要素>
<要素1 要素名="h1" 属性名="style"></要素1>
<要素2 要素名="h2" 属性名="style"></要素2>
<要素3 要素名="h3" 属性名="style"></要素3>
<要素4 要素名="h4" 属性名="style"></要素4>
<要素5 要素名="h5" 属性名="style"></要素5>
<要素6 要素名="h6" 属性名="style"></要素6>
</要素>
【sample010.xsl】
<?xml version="1.0" encoding="Shift_JIS" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="Shift_JIS" />
<xsl:template match="要素">
<html>
<head><title>要素と属性の生成</title></head>
<body>
<h2>要素と属性の生成</h2>
<xsl:element name="{要素1/@要素名}">
<xsl:attribute name="{要素1/@属性名}">color:red;</xsl:attribute>てすと
</xsl:element>
<xsl:element name="{要素2/@要素名}">
<xsl:attribute name="{要素2/@属性名}">color:blue;</xsl:attribute>てすと
</xsl:element>
<xsl:element name="{要素3/@要素名}">
<xsl:attribute name="{要素3/@属性名}">color:green;</xsl:attribute>てすと
</xsl:element>
<xsl:element name="{要素4/@要素名}">
<xsl:attribute name="{要素4/@属性名}">color:yellow;</xsl:attribute>てすと
</xsl:element>
<xsl:element name="{要素5/@要素名}">
<xsl:attribute name="{要素5/@属性名}">color:orange;</xsl:attribute>てすと
</xsl:element>
<xsl:element name="{要素6/@要素名}">
<xsl:attribute name="{要素6/@属性名}">color:silver;</xsl:attribute>てすと
</xsl:element>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
【結果】