首页 > 解决方案 > 操作 XML 元素中的文本

问题描述

在我的 XSL 文档中,我有这个:

<xsl:if test="notification_data/incoming_request/note != ''">
<tr>
<td><h2><b>@@request_note@@: </b> <xsl:value-of select="notification_data/incoming_request/note"/></h2></td>
</tr>
</xsl:if>

XML note 元素中的文本实际上是由 || 分隔的三段数据拼凑在一起的。它是由我们的供应商以这种方式提供的。

<note>||Christie, James||1234567||Lutheran College</note>

有没有办法从同一个 XSL 文档中解析出这三段数据并选择要在信函上打印的内容?

谢谢你的帮助!

标签: xmlxslt

解决方案


太感谢了!我使用的是 XSLT 1.0,所以我使用嵌套的 substring-before 和 substring-after 来解决这个问题。对于任何有兴趣的人:

<xsl:value-of select="substring-before(substring-after(notification_data/incoming_request/note,'||'),'||')"/> - <xsl:value-of select="substring-after(substring-after(substring-after(notification_data/incoming_request/note,'||'),'||'),'||')"/>

结果:

Christie,James - Lutheran College 

这就是我们想要打印的。是的,数据元素的顺序总是相同的。再次感谢!


推荐阅读