使用XSLT拆分标点符号列表

时间:2015-10-08 08:46:10

标签: xml xslt tokenize

数据

我有以下格式的xml:

<a>
 <b>this</b>
 <b>is></b>
 <b>ok</b>
 <b>this</b>
 <b>is</b>
 <b>not</b>"!.
</a>

期望的输出

所需的输出是:

this
is
ok
this
is
not
"
!
.

具体问题

我的问题是:一旦我使用text()捕获标签外的标点符号,我会将它们标记为什么?

我正在使用XSLT 2.0,我尝试过使用

tokenize(text(),'.')

但无效。

注意:此问题源自this其他问题。

1 个答案:

答案 0 :(得分:2)

您可以在另一个问题@Dimitre Novatchev中使用here建议的string-to-codepoints()codepoints-to-string()功能,例如:

<xsl:template match="b"><xsl:value-of select="."/></xsl:template>

<xsl:template match="a/text()[normalize-space()]">
    <xsl:for-each select="string-to-codepoints(normalize-space(.))">
      <xsl:text>&#xa;</xsl:text>
      <xsl:sequence select="codepoints-to-string(.)"/>
    </xsl:for-each>
</xsl:template>

<强> Xsltransform Demo

输出

this
is&gt;
ok
this
is
not
"
!
.
相关问题