how to check repeated elements in as string sequen

2019-09-03 10:00发布

问题:

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))">...


标签: xslt