xml - 操作 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 文档中解析出这三段数据并选择要在信函上打印的内容?
谢谢你的帮助!
解决方案
太感谢了!我使用的是 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
这就是我们想要打印的。是的,数据元素的顺序总是相同的。再次感谢!
推荐阅读
- typescript - Axios 作为特定类型返回
- html - 始终覆盖首屏的主要内容?
- java - 数据类型名称与变量名称相同,这在Java中如何工作
- c# - 比较 ActiveDirectory 中的数据并存储到 db
- javascript - TypeError:无法读取未定义的属性“innerText” - 从 eshop 中删除
- java - 预订后显示预订时出现 ArrayIndexOutOfBounds 异常错误 - Java
- java - 来自编译器的未经检查的强制转换警告
- mysql - 在 MariaDB 中对大于 60 GB 的表运行基本的 SQL 查询
- c# - WPF 中 Page 中 Window 的 Activated 事件的等效或最接近的匹配是什么?
- nginx - 有没有办法在 nginx 上添加包含代理服务器名称的响应标头?