【发布时间】:2011-02-11 15:36:45
【问题描述】:
在下面的 XSL 中,每次 xsl:when 得到满足时,我都想附加尽可能多的 <a> 和 </a> 标记。但是需要在标签内填充的数据应该只有一次。我在最后展示了预期的输出。
<xsl:param name="insert-file" as="document-node()" />
<xsl:template match="*">
<xsl:variable name="input">My text</xsl:variable>
<xsl:variable name="Myxml" as="element()*">
<xsl:call-template name="populateTag">
<xsl:with-param name="nodeValue" select="$input"/>
</xsl:call-template>
</xsl:variable>
<xsl:copy-of select="$Myxml"></xsl:copy-of>
</xsl:template>
<xsl:template name="populateTag">
<xsl:param name="nodeValue"/>
<xsl:for-each select="$insert-file/insert-data/data">
<xsl:choose>
<xsl:when test="@index = 1">
<a><xsl:value-of select="$nodeValue"></xsl:value-of></a>
</xsl:when>
</xsl:choose>
</xsl:for-each>
</xsl:template>
当前输出:
<?xml version="1.0" encoding="UTF-8"?>
<a>我的短信</a>
<a>我的短信</a>
<a>我的短信</a>
<a>我的短信</a>
我希望模板“populateTag”向我返回以下格式的 xml。我如何修改模板“populateTag”以实现相同。
模板“populateTag”的预期输出:
<?xml version="1.0" encoding="UTF-8"?>
<a><a><a><a>我的短信</a></a></a></a>
请说出你的想法。
【问题讨论】: