0
我需要以特定顺序获取属性,所以我在特定的一组名称上使用循环。我想做一些像@ $属性或类似@的东西。但只是使用。给我的名字本身,而不是我想要的属性的价值。使用变量作为属性名称
基本上不是每行都说“标题”和“艺术家”,我想要的是实际的标题和艺术家。
的hello.xml:
<?xml version="1.0" encoding="UTF-8"?>
<results>
<r title="Empire Burlesque" artist="Bob Dylan" />
<r title="Hide your heart" artist="Bonnie Tyler" />
<r title="Greatest Hits" artist="Dolly Parton" />
</results>
hello.xsl:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template name="boxNames"> <!-- not used as template -->
<name>title</name>
<name>artist</name>
</xsl:template>
<xsl:template match="/">
<xsl:variable name="boxNames" select="document('')/xsl:stylesheet/xsl:template[@name='boxNames']/name" />
<html>
<body>
<h2>My CD Collection</h2>
<table border="1">
<tr bgcolor="#9acd32">
<xsl:for-each select="$boxNames">
<th style="text-align:left"><xsl:value-of select="." /></th>
</xsl:for-each>
</tr>
<xsl:for-each select="results/r">
<tr>
<xsl:for-each select="$boxNames">
<td><xsl:value-of select="."/></td>
</xsl:for-each>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
输出:
<html>
<body>
<h2>My CD Collection</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th style="text-align:left">title</th>
<th style="text-align:left">artist</th>
</tr>
<tr>
<td>title</td>
<td>artist</td>
</tr>
<tr>
<td>title</td>
<td>artist</td>
</tr>
<tr>
<td>title</td>
<td>artist</td>
</tr>
</table>
</body>
</html>Execution time: 88.941623ms