使用xslt提取属性
我在文件中包含以下xml内容:使用xslt提取属性,xslt,Xslt,我在文件中包含以下xml内容: <testsuite errors="1" failures="1" name="unittest.suite.TestSuite" tests="3" time="6.540"> <properties> <property name="comp1" value="0.0.0.0:80=0.0.1"/> <property name="comp2" value="12.34.56.78:80=0.0.
<testsuite errors="1" failures="1" name="unittest.suite.TestSuite" tests="3" time="6.540">
<properties>
<property name="comp1" value="0.0.0.0:80=0.0.1"/>
<property name="comp2" value="12.34.56.78:80=0.0.1"/>
使用xsl。我尝试了以下方法
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<table border="1">
<tr bgcolor="#9acd32">
<th>Name</th>
<th>Value</th>
</tr>
<xsl:for-each select="testsuite/properties/property">
<tr>
<td><xsl:value-of select="name"/></td>
<td><xsl:value-of select="value"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
名称
价值
这只是一张空桌子。如何正确地做到这一点?我在网上只找到了一些复杂的例子。如果有人知道这方面的好教程,我也欢迎 试试看
<td><xsl:value-of select="@name"/></td>
<td><xsl:value-of select="@value"/></td>
访问属性时,您需要在名称前添加@
。请尝试
<td><xsl:value-of select="@name"/></td>
<td><xsl:value-of select="@value"/></td>
当访问属性时,您需要在名称之前添加
@
。@
用于属性,如果不使用,则默认情况下将其视为元素
因此,如果XML如下所示,则代码工作正常:
<testsuite errors="1" failures="1" name="unittest.suite.TestSuite" tests="3" time="6.540">
<properties>
<property>
<name>comp1</name>
<value>0.0.0.0:80=0.0.1</value>
</property>
<property>
<name>comp2</name>
<value>12.34.56.78:80=0.0.1</value>
</property>
..........
........
@
用于属性,如果不使用,则默认情况下它将被视为元素
因此,如果XML如下所示,则代码工作正常:
<testsuite errors="1" failures="1" name="unittest.suite.TestSuite" tests="3" time="6.540">
<properties>
<property>
<name>comp1</name>
<value>0.0.0.0:80=0.0.1</value>
</property>
<property>
<name>comp2</name>
<value>12.34.56.78:80=0.0.1</value>
</property>
..........
........