【发布时间】:2020-03-01 18:39:08
【问题描述】:
我有一个 xml 消息——由一个相当基本的 XML 编写器创建(在某些情况下它不会迭代重复记录)——这意味着我们有一个文本字符串,其中包含必要的分隔文本块。 在 XML 工具中,我们能够编写一个非常长的文本字符串,但我们能够添加行尾/换行指示符。 (TXNNTX,但可以是除了 xml 标签之外的任何东西) 作为一个字符串,它可以在 XML 文件的任何地方找到。
字符串将是:
<causale>This is text that we need in line one TXNNTX We then need test to follow again that may have something important to say TXNNTX Then another line which is longer and longer and longer and longer and longer and longer and longer TXNNTX The maybe shorter TXNNTX or dots TXNNTX .............................................................................</causale>
我们需要找到 TXNNTX 并将其替换为输出变为(新行仅用于说明):
<causale>This is text that we need in line one </causale>
<causale> We then need test to follow again that may have something important to say </causale>
<causale> Then another line which is longer and longer and longer and longer and longer and longer and longer </causale>
<causale> The maybe shorter </causale>
<causale> or dots </causale>
<causale> .............................................................................</causale>
字符数最长可达 2000 个字符 尝试了许多不同的脚本,但要么是因为我们在内部使用了“,这似乎混淆了我对脚本的基本掌握
【问题讨论】:
-
使用 XSLT 2,这是
xsl:analyze-string的工作,而使用 XSLT 3,您可以使用analyze-string函数来更轻松地完成这项工作。了解您是否可以使用 XSLT 或 3 处理器,例如 Saxon 9。