我的输入如下:
<party>
<name>Jessica's 18th birthday</name>
<participants>
<participant>
<name>Jessica</name>
</participant>
<participant>
<name>Aron</name>
</participant>
<participant>
<name>Steve</name>
</participant>
</participants>
</party>我已经创建了一个名为template的实用程序,它给出了一个party元素,它将所有参与者的名称转换为一个逗号分隔的字符串:
<xsl:template name="list-participants">
<xsl:param name="party"/>
<xsl:value-of select="$party/participants/participant ! name" separator=";"/>
</xsl:template>我在这里使用XSLT3。我在样式表中使用所谓的内容值模板(CVT),因为这使事情变得更加可读性:
name: {name}而不是
name: <xsl:value-of select="name"/>现在我的问题是:这里是否可以使用这些{...}扩展来执行/调用list-participants模板?基本上,我想做以下几点:
<xsl:template match="party">
The following persons will be present at the party: {list-participants(party=.)}
</xsl:template>在这里,.引用当前的party元素。(以上都是伪核心,希望它能让我的问题更加清晰,不会让快速读者感到困惑。)
您可以说,我希望执行函数调用,如过程语言中所示。
在XSLT3中这(在某种程度上)可能吗?
发布于 2019-09-11 08:07:35
如果使用的是函数,而不是命名模板,则可以这样做。
<xsl:template match="party">
<xsl:text>The following persons will be present at the party:{my:list-participants(.)}</xsl:text>
</xsl:template>
<xsl:function name="my:list-participants">
<xsl:param name="party"/>
<xsl:value-of select="$party/participants/participant/name" separator=";"/>
</xsl:function>可以根据您的喜好定义名称空间前缀my的位置。
请参阅http://xsltfiddle.liberty-development.net/gWEamKN
https://stackoverflow.com/questions/57884645
复制相似问题