我正在尝试将播放器名称的格式设置为LAST,F,而不是全名。
所以基本上我想在每个逗号后将字符串切成2个空格并添加。(句点)
以下是XML的示例:
<fbgame>
<team>
<player name="LASTNAME, FIRSTNAME"></player>
</team>
</fbgame>
这是xslt代码块
<name>
<xsl:value-of select="@name"/>
</name>
答案 0 :(得分:1)
使用xslt 2.0,
<name>
<xsl:variable name="fullname" select="tokenize(@name, ',')" />
<xsl:value-of select="concat($fullname[1], ',',substring($fullname[2],1,2),'.')"/>
</name>
答案 1 :(得分:1)
XSLT 1.0
<xsl:template match="player">
<name>
<xsl:value-of select="substring-before(@name, ', ')" />
<xsl:text>, </xsl:text>
<xsl:value-of select="substring(substring-after(@name, ', '), 1, 1)" />
<xsl:text>.</xsl:text>
</name>
</xsl:template>
或者,如果您愿意:
<xsl:template match="player">
<name>
<xsl:variable name="last" select="substring-before(@name, ', ')" />
<xsl:value-of select="substring(@name, 1, string-length($last) + 3)" />
<xsl:text>.</xsl:text>
</name>
</xsl:template>
答案 2 :(得分:1)
另一个XSLT 2.0选项:
<xsl:template match="player">
<name>
<xsl:value-of select="replace(@name,'([^,]+, .).*','$1.')"/>
</name>
</xsl:template>