我有以下xslt。我注意到有时元素名称“元组”有一个属性。我想删除该属性并将其添加为元素。我添加了测试来验证'元组'是否有一个属性,但它返回一个空白'ecatalogue'元素。xslt测试是否存在属性
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8"
indent="yes" />
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()" />
</xsl:copy>
</xsl:template>
<xsl:template match="atom">
<xsl:element name="{@name}">
<xsl:apply-templates />
</xsl:element>
</xsl:template>
<xsl:template match="table">
<xsl:element name="{@name}">
<xsl:apply-templates />
</xsl:element>
</xsl:template>
<!--this test doesn't work properly -->
<xsl:template match="tuple">
<xsl:choose>
<xsl:when test="@name">
<xsl:apply-templates />
</xsl:when>
<xsl:otherwise>
<!-- nothing to do
the node should stay the same
-->
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- end test -->
</xsl:stylesheet>
结果我用上面的这个模板。
<ecatalogue>
</ecatalogue>
https://gist.github.com/guinslym/5ce47460a31fe4c4046b
如果您提供了示例源XML文件以及您希望将其转换为什么,这将会很有帮助。 – Mitch 2015-02-07 23:44:53
感谢米奇!我的要点链接没有工作... – 2015-02-07 23:48:36
@PapoucheGuinslyzinho将属性始终是'@名称',不能有另一个名字? – 2015-02-08 03:24:54