前の質問で投稿したスタイルシートから構築すると、要素宣言内で各Attributes/Attribute
要素を繰り返し処理し、構築中の要素の属性を構築できます。
Object
そのforループ内の要素ノードに「立っている」ので、次のAttributes/Attribute
ように要素を反復処理できます。
<xsl:for-each select="Attributes/Attribute">
<xsl:attribute name="{@name}"><xsl:value-of select="current()"/></xsl:attribute>
</xsl:for-each>
スタイルシートに適用:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
>
<xsl:output method="html" indent="yes"/>
<xsl:template match="/">
<html>
<head>
</head>
<body>
<xsl:for-each select="Page/Object">
<xsl:element name="{Type}" >
<xsl:for-each select="Attributes/Attribute">
<xsl:attribute name="{@name}"><xsl:value-of select="current()"/></xsl:attribute>
</xsl:for-each>
<xsl:value-of select="Value"/>
</xsl:element>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
これは、同じ出力を実現する別の方法ですが、apply-templates
代わりにfor-each
.
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
>
<xsl:output method="html" indent="yes"/>
<xsl:template match="/">
<html>
<head>
</head>
<body>
<xsl:apply-templates select="Page/Object" />
</body>
</html>
</xsl:template>
<xsl:template match="Object">
<xsl:element name="{Type}" >
<xsl:apply-templates select="Attributes/Attribute" />
<xsl:apply-templates select="Value" />
</xsl:element>
</xsl:template>
<xsl:template match="Attribute">
<xsl:attribute name="{@name}"><xsl:value-of select="."/></xsl:attribute>
</xsl:template>
</xsl:stylesheet>