Here is a more efficient solution O(N) vs. O(N^2) for the accepted answer:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:template match="text()" name="skipAfterDots">
<xsl:param name="pTotalString" select="."/>
<xsl:param name="pTotalLength" select="string-length(.)"/>
<xsl:param name="pPosition" select="1"/>
<xsl:param name="pLastFound" select="-1"/>
<xsl:choose>
<xsl:when test="$pPosition > $pTotalLength">
<xsl:value-of select="substring($pTotalString, $pLastFound + 1)"/>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="vIsDot" select=
"substring($pTotalString, $pPosition, 1) = '.'"/>
<xsl:call-template name="skipAfterDots">
<xsl:with-param name="pTotalString" select="$pTotalString"/>
<xsl:with-param name="pTotalLength" select="$pTotalLength"/>
<xsl:with-param name="pLastFound" select=
"$pLastFound * not($vIsDot) + $pPosition * $vIsDot"/>
<xsl:with-param name="pPosition" select="$pPosition+1"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
When this transformation is applied on the following XML document:
<t>M:Namespace.Class.Method(Something a, Something b)</t>
the wanted, correct result is produced:
Method(Something a, Something b)
Explanation:
This solution doesn't contain any call to the substring-after()
function. Instead, at each step only the one character of the string is compared for equality with the dot character. Because there are at most N characters, this is O(N) -- linear complexity.
On the contrary, the accepted answer calls the substring-after()
function on every step. In the worst case there could be N dots and thus this would be O(N^N) -- quadratic complexity.
Note: We make the reasonable assumption that in both solutions locating the k-th character of a string is O(1).