我熟悉使用模板,键关机属性如下(如钥匙关闭的foo
存在):如何实现属性的特定模板没有冗余
<xsl:template match="something[@foo]">
<xsl:template match="something[not(@foo)]">
然而,如果太多的内容这些模板是一样的,有没有更好的方式仍然使用模板,因为社区似乎更喜欢它们?或者只是使用xsl:choose
的解决方案。显然最好不要编写必须在两个模板中维护的重复代码。
编辑: 这是我的一组特定的模板:
<xsl:template match="item[not(@format)]">
<td class="{current()/../@name}_col status_all_col">
<xsl:value-of select="current()"/>
<xsl:value-of select="@units"/>
</td>
</xsl:template>
<xsl:template match="item[@format]">
<td class="{current()/../@name}_col status_all_col">
<xsl:value-of select="format-number(current(), @format)"/>
<xsl:value-of select="@units"/>
</td>
</xsl:template>
这里是我当前使用中进行选择:
<xsl:template match="item">
<td class="{current()/../@name}_col status_all_col">
<xsl:choose>
<xsl:when test="@format">
<xsl:value-of select="format-number(current(), @format)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="current()"/>
</xsl:otherwise>
</xsl:choose>
<xsl:value-of select="@units"/>
</td>
</xsl:template>
答案取决于两个模板的实际内容。 - P.S.使用'xsl:choose'没有任何问题。 –
我添加了我的特定模板。 – Bryant