请帮忙。需要能够选择/提取位于相同重复字符之间的字符串。
示例:狗从篱笆中逃出〜然后跑过马路〜进入交通,但是没有受到伤害。我们非常高兴狗是安全的。
遵循此格式AAA = BBBBB = CCCCCCCCCCCCCCCC = D = FFFFF = GG = H,尝试应用以下方法,但无法使用此方法提取:
<xsl:value-of select="substring-before(
substring-after ($vari, , '=')
, '=')"/>
对于BBBBB
或者:
<xsl:value-of select="substring-before(
substring-after ( substring-after ($vari, '='), '=')
, '=')"/>
对于CCCCCCCCCCCCCC。
非常感谢任何帮助。
答案 0 :(得分:2)
此转化:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="t">
<xsl:param name="pIndex" select="0"/>
<xsl:variable name="vToken" select=
"substring-before(substring(concat(.,'~'), $pIndex+1), '~')"/>
<xsl:variable name="vnewIndex" select="$pIndex+string-length($vToken)+1"/>
<token>
<xsl:value-of select="$vToken"/>
</token>
<xsl:apply-templates select="self::node()[not($vnewIndex >= string-length(.))]">
<xsl:with-param name="pIndex" select="$vnewIndex"/>
</xsl:apply-templates>
</xsl:template>
</xsl:stylesheet>
应用于提供的XML文档:
<t>The dog escaped ~ from the fence ~ and ran across the road ~ into traffic, but did not ~ get hurt thankfully. We are ~ very happy the dog is safe.</t>
生成想要的正确结果:
<token>The dog escaped </token>
<token> from the fence </token>
<token> and ran across the road </token>
<token> into traffic, but did not </token>
<token> get hurt thankfully. We are </token>
<token> very happy the dog is safe.</token>