how to check repeated elements in as string sequence/array?

*爱你&永不变心* 提交于 2020-01-17 03:57:17

问题


I am using xslt 1.0 stylesheet to worlk on xml file data.

I have a variable in xslt which conatins many string separated by white space or new line charater.

i.e. the variable is "ServiceList", when I print it using follwong,

<xsl:value-of select="$ServiceList"/>

It prints following out put

hgd.sdf.gsdf sdf.sdh.duyg dsf.sdf.suos
jhs.sdu.sdfi
hdf.sdi.seij dsf.dsf.diuh
edr.sdi.sdhg dfh.dfg.dfg.fdg.idjf kjs.dfh.dfgj djg.dfs.dgji  

I used follwing code to get each string separately.

<xsl:variable name="tokenizedSample" select="str:tokenize($ServiceList,'&#xa;')"/>
  <xsl:for-each select="$tokenizedSample">
      <xsl:variable name="serviceProvide" select="."/>
         <xsl:variable name="tokenized1" select="str:tokenize($serviceProvide,' ')"/>
         <xsl:for-each select="$tokenized1">
            <xsl:variable name="serviceP" select="."/>
                  <xsl:value-of select="$serviceP"/>
  </xsl:for-each>
 </xsl:for-each>

the above code give me each string as separate one.

I have to chek is there any repeating string in above sequence/array. If it repeates it should show me the string is repeating.


回答1:


This would be so much easier in XSLT 2.0

<xsl:variable name="tokenizedSample" select="tokenize($ServiceList, '&#xa;')"/>
<xsl:if test="count($tokenizedSample) != count(distinct-values($tokenizedSample))">...


来源:https://stackoverflow.com/questions/6054688/how-to-check-repeated-elements-in-as-string-sequence-array

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!