Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在XSLT中为属性使用多个值_Xslt - Fatal编程技术网

如何在XSLT中为属性使用多个值

如何在XSLT中为属性使用多个值,xslt,Xslt,我想在XSLT中为属性使用多个值 输入: <contrib contrib-type="author"> <name> <surname>Khorana</surname> <given-names>Alok A.</given-names> </name> <degrees>MD</degrees> </contri

我想在XSLT中为属性使用多个值

输入:

<contrib contrib-type="author">
     <name>
         <surname>Khorana</surname>
         <given-names>Alok A.</given-names>
     </name>
     <degrees>MD</degrees>
</contrib>
<contrib contrib-type="author">
     <name>
         <surname>Holand</surname>
         <given-names>Gamak J.</given-names>
     </name>
     <degrees>PhD</degrees>
</contrib>

霍拉纳
阿洛克A。
医学博士
荷兰
伽马克J。
博士
输出应为:

<fieldSet name="Author" value="Alok A. Khorana, MD Gamak J. Holand, PhD"/>

试用代码:

<xsl:template name="take-author">
    <tps:fieldSet name="Author">
        <xsl:attribute name="value">
            <xsl:value-of select="concat(descendant::contrib[@contrib-type='author']/name/given-names,descendant::contrib[@contrib-type='author']/name/surname)"/>
        </xsl:attribute>
    </tps:fieldSet>
</xsl:template>

但是我在尝试上面的代码时遇到了以下错误

不允许将多个项的序列作为第一个参数 concat()的定义


得到该消息的事实表明您正在使用XSLT2.0,它不允许将多个元素的序列作为需要字符串参数的函数的参数

如果您确实在使用XSLT2.0(或更高版本),您可以这样做

<xsl:value-of select="descendant::contrib[@contrib-type='author']/concat(name/given-names, ' ', name/surname, ', ', degrees)" separator=" " />
<xsl:for-each select="descendant::contrib[@contrib-type='author']">
    <xsl:if test="position() > 1"><xsl:text> </xsl:text></xsl:if>
    <xsl:value-of select="concat(name/given-names, ' ', name/surname, ', ', degrees)" />
</xsl:for-each>