在下面的 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
>
请给出你的想法。