Znajdź liczbę wystąpień podciągu w ciągu znaków w xslt
Piszę skrypt, aby znaleźć liczbę wystąpień podciągu w ciągu znaków w XSLT. Zajmuje to zbyt wiele czasu, gdy chcę przejść przez ponad 200 tysięcy rekordów. Czy ktoś może mi pomóc wskazać niektóre zmiany, aby uczynić je szybszym, lub w inny sposób uzyskać liczbę wystąpień?
Mówię o podłożu, a nie postaci - więc nie mówię otranslate()
funkcjonować.
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>
<xsl:template match="/">
<Root>
<NoofOccurane>
<xsl:call-template name="GetNoOfOccurance">
<xsl:with-param name="String" select="'My Name is Rohan and My Home name is also Rohan but one of my firend honey name is also Rohan'"/>
<xsl:with-param name="SubString" select="'Rohan'"/>
</xsl:call-template>
</NoofOccurane>
<NoofOccurane>
<xsl:call-template name="GetNoOfOccurance">
<xsl:with-param name="String" select="'My Name is Rohan and My Home name is also Rohan but one of my firend honey name is also Rohan'"/>
<xsl:with-param name="SubString" select="'Sohan'"/>
</xsl:call-template>
</NoofOccurane>
<NoofOccurane>
<xsl:call-template name="GetNoOfOccurance">
<xsl:with-param name="String" select="'My Name is Rohan and My Home name is also Mohan but one of my firend honey name is also Rohan'"/>
<xsl:with-param name="SubString" select="'Mohan'"/>
</xsl:call-template>
</NoofOccurane>
</Root>
</xsl:template>
<xsl:template name="GetNoOfOccurance">
<xsl:param name="String"/>
<xsl:param name="SubString"/>
<xsl:variable name ="LenString" select="string-length($String)" />
<xsl:variable name ="LenSubString" select="string-length($SubString)" />
<xsl:variable name ="ReplaceString">
<xsl:call-template name="replace-string">
<xsl:with-param name="text" select="$String"/>
<xsl:with-param name="replace" select="$SubString"/>
<xsl:with-param name="with" select="''"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name ="NewLenString" select="string-length($ReplaceString)" />
<xsl:variable name ="DiffLens" select ="number($LenString)-number($NewLenString)" />
<xsl:choose>
<xsl:when test ="$NewLenString=0 and $LenSubString >0">
<xsl:value-of select ="1"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select ="number($DiffLens) div number($LenSubString)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- Template to Replace function -->
<xsl:template name="replace-string">
<xsl:param name="text"/>
<xsl:param name="replace"/>
<xsl:param name="with"/>
<xsl:choose>
<xsl:when test="contains($text,$replace)">
<xsl:value-of select="substring-before($text,$replace)"/>
<xsl:value-of select="$with"/>
<xsl:call-template name="replace-string">
<xsl:with-param name="text" select="substring-after($text,$replace)"/>
<xsl:with-param name="replace" select="$replace"/>
<xsl:with-param name="with" select="$with"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$text"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
wynik to
<Root>
<NoofOccurane>3</NoofOccurane>
<NoofOccurane>0</NoofOccurane>
<NoofOccurane>1</NoofOccurane>
</Root>