示例 xml 文件如下所示
<a>
<apple color="red"/>
<banana color="yellow"/>
<sugar taste="sweet"/>
<cat size="small"/>
</a>
我应该在 XSLT 中编写什么才能获得下面的示例输出?
<AAA>apple</AAA>
<BBB>color</BBB>
<CCC>red</CCC>
<AAA>banana</AAA>
<BBB>color</BBB>
<CCC>yellow</CCC>
下面是我编写的 XSLT 文件,但我不知道如何提取该值。
<xsl:template match="*/*">
<AAA>
<xsl:value-of select="name()"/>
</AAA>
<xsl:apply-templates select="@*"/>
</xsl:template>
<xsl:template match="@*">
<BBB>
<xsl:value-of select="name()"/>
</BBB>
</xsl:template>
最佳答案
你的xml应该是这样的
<catalog>
<fruit>
<name>apple </name>
<color>red</color>
</fruit>
<fruit>
<name>banana </name>
<color>yellow</color>
</fruit>
</catalog>
XSLT 为:
<xsl:for-each select="catalog/fruit">
<tr>
<td><AAA><xsl:value-of select="title"/></AAA></td>
<td><BBB>color</BBB></td>
<td><CCC><xsl:value-of select="color"/></CCC></td>
</tr>
</xsl:for-each>
关于xml - 提取标签名称、属性及其值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8555524/