このスタイルシート:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="pSeparators">
	 ,.;:?!()'"</xsl:param>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="p/text()" name="tokenize">
<xsl:param name="pString" select="."/>
<xsl:param name="pMask"
select="translate(.,translate(.,$pSeparators,''),'')"/>
<xsl:param name="pCount" select="1"/>
<xsl:choose>
<xsl:when test="not($pString)"/>
<xsl:when test="$pMask">
<xsl:variable name="vSeparator"
select="substring($pMask,1,1)"/>
<xsl:variable name="vString"
select="substring-before($pString,$vSeparator)"/>
<xsl:call-template name="tokenize">
<xsl:with-param name="pString" select="$vString"/>
<xsl:with-param name="pMask"/>
<xsl:with-param name="pCount" select="$pCount"/>
</xsl:call-template>
<xsl:value-of select="$vSeparator"/>
<xsl:call-template name="tokenize">
<xsl:with-param name="pString"
select="substring-after($pString,$vSeparator)"/>
<xsl:with-param name="pMask"
select="substring($pMask,2)"/>
<xsl:with-param name="pCount"
select="$pCount + boolean($vString)"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<span class="word-{$pCount}">
<xsl:value-of select="$pString"/>
</span>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
出力:
<p><span class="word-1">This</span> <span class="word-2">is</span> <span class="word-3">my</span> <span class="word-4">text</span>!</p>
注:トークン化、いくつかの区切りによります。 を編集:より良い名前。セパレータシーケンスに空白文字を追加する。
句読点はpreviusに属していますか? –