如何在xslt中连接foreach?

时间:2018-02-20 09:35:59

标签: xslt

我的xslt中有以下结构 -

   <Identification>
                    <xsl:for-each select="DataPartner">                 

 <xsl:variable name="var:v30" select="userCSharp:LogicalEq(string(../../Demo/@name) , &quot;Description&quot;)" />
                        <xsl:if test="string($var:v30)='true'">
                          <Identifier>
                              <xsl:value-of select="Demo/demo/text()" />
                              <xsl:text>,</xsl:text>
                          </Identifier>
                        </xsl:if>
                      </xsl:for-each>

                    </Identification>

输入xml -

<DataPartner>
                      <Demo name="Description">
            <demo>demo11</demo>
          </Demo>
           <Demo name="Description">
            <demo>demo12</demo>
          </Demo>
                            <DataPartner>

预期产出 -

demo11 , demo12

1 个答案:

答案 0 :(得分:2)

如果打算连接所有demo元素文本,其中Demo名称是&#34;描述&#34;,那么这就是你如何做到的....

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:output method="html" indent="yes" />

  <xsl:template match="DataPartner">
    <Identifier>
      <xsl:for-each select="Demo[@name='Description']">
        <xsl:if test="position() &gt; 1">, </xsl:if>
        <xsl:value-of select="demo" />
      </xsl:for-each>
    </Identifier>
  </xsl:template>
</xsl:stylesheet>