这是this问题的延伸。
我有一个像这样的XML片段
<lines>
<item><code>1.1</code><amt>1000.00</amt></item>
<item><code>1.3.1</code><amt>2000.00</amt></item>
<item><code>1.3.2</code><amt>3000.00</amt></item>
<item><code>2.1</code><amt>4000.00</amt></item>
...
</lines>
我想要添加一些预定义的代码集。 感谢您的建议,现在我可以这样做:
<xsl:value-of select="sum(item[code=1.1 or code=1.2 or
code=1.3.1 or code=1.3.2]/amt)"/>
但是我想创建一个模板并用简单易读的params调用它来列出所有需要的代码。类似的东西:
... <xsl:with-param name="set" select="'1.1, 1.2'"/> ...
or
... <xsl:with-param name="set" select="'(1.1)|(1.2)'"/> ...
然后在被调用的模板中执行类似:
的操作<xsl:value-of select="sum(item[code in $set]/amt)"/>
是否可以在XSLT中使用?
P.S。我正在使用SAP XSLT处理器,它非常受限制,例如它没有match()。
答案 0 :(得分:0)
<xsl:variable name="set"
select="'(1.1)(1.2)(2.1)'"/>
<xsl:template match="/">
<answer>
<xsl:call-template name="sum-it">
<xsl:with-param name="set" select="$set"/>
<xsl:with-param name="items" select="lines/item"/>
</xsl:call-template>
</answer>
</xsl:template>
<xsl:template name="sum-it">
<xsl:param name="set"/>
<xsl:param name="items"/>
<xsl:value-of select="sum(
$items[contains($set,concat('(', code ,')'))]/amt)"/>
</xsl:template>