2012-10-17 225 views
1

我想连接所有数字(如1 + 0 + 1 + 1 + 1)。请注意逗号分隔值可能增加或减少。下面是XML XSL代码:concat逗号分隔的字符串值

的xml:

<?xml version="1.0" encoding="UTF-8"?> 
<?xml-stylesheet type="text/xsl" href="class.xsl"?> 
<root><LIST> 
<ROLE>s1</ROLE> 
<STATUS>yes</STATUS> 
</LIST> 
<LIST> 
<ROLE>s1</ROLE> 
<STATUS>d</STATUS> 
</LIST> 
<LIST> 
<ROLE>Member</ROLE> 
<STATUS>no</STATUS> 
</LIST> 
<LIST> 
<ROLE>Member</ROLE> 
<STATUS>no</STATUS> 
</LIST> 
<LIST> 
<ROLE>Member</ROLE> 
<STATUS>yes</STATUS> 
</LIST> 
</root> 

的xsl:

<?xml version="1.0" ?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    <xsl:template match="/"><html> 
    <h2> 
<xsl:variable name="orgactcount"> 
    <xsl:for-each select="/root/LIST"> 
    <xsl:if test = "STATUS='yes'"> 
<xsl:value-of select="'1,'"/> 
</xsl:if> 
</xsl:for-each> 
</xsl:variable> 
<xsl:value-of select="$orgactcount"/> 
</h2></html> 
    </xsl:template> 
</xsl:stylesheet> 

orgactcount变量具有1,1,值,它必须concated像1 + 1 ... 。我试图分割所有的逗号分隔值,然后操纵...但我不能...有没有人有想法

+0

你究竟想干什么?请详细说明一下,我没有看到问题所在。 – Jost

+0

我已更新我的代码。请看一看! – ezhil

+0

您可以显示您当前的输入XML文档以及您的预期输出,因为这会使事情变得更加清晰。谢谢。 –

回答

2

我编辑你的XSLT加入translate功能。

<?xml version="1.0" ?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    <xsl:template match="/"> 
    <html> 
     <h2> 

     <xsl:variable name="orgactcount"> 
      <xsl:for-each select="/root/LIST"> 
      <xsl:if test = "STATUS='yes'"> 
       <xsl:value-of select="'1,'"/> 
      </xsl:if> 
      </xsl:for-each> 
     </xsl:variable> 

     <xsl:variable name="formattedorgactcount" select="translate($orgactcount, ',', '+')"/> 
     <xsl:value-of select="$formattedorgactcount"/> 

     </h2> 
    </html> 
    </xsl:template> 
</xsl:stylesheet> 

以下对您也有帮助。

XSLT string replace

+0

它按预期工作。感谢Madurika Welivita – ezhil

+1

@ezhil在Stackoverflow中感谢的方式是接受答案并投票支持...干杯... –

+0

@ezhil为答案投赞成票,通过点击箭头头..谢谢 –