使用 XSLT 拆分标点符号列表

Split a list of punctuation chars using XSLT

数据

我有一个 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 其他问题。

您可以按照 @Dimitre Novatchev in another question 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
"
!
.