xslt - XSLT - 用特定字符分隔的分割字符串
问题描述
我有一个这样的xml,
<doc>
<para>A brief 23 spell$of hea#vy rain$forc^%ed an early+ lunch$98@with nine</para>
</doc>
我需要从文本中存在的每个 $ 中断开文本字符串。
所以预期的输出应该是,
<doc>
<para>A brief 23 spell</para>
<para>of hea#vy rain</para>
<para>forc^%ed an early+ lunch</para>
<para>98@with nine</para>
</doc>
谁能建议我如何使用 XSLT 1.0 做到这一点?
解决方案
尝试这个
<xsl:template match="para">
<xsl:call-template name="spilit">
<xsl:with-param name="text" select="."/>
</xsl:call-template>
</xsl:template>
<xsl:template name="spilit">
<xsl:param name="text"/>
<xsl:choose>
<xsl:when test="contains($text, '$')">
<para><xsl:value-of select="substring-before($text, '$')"/></para>
<xsl:call-template name="spilit">
<xsl:with-param name="text" select="substring-after($text, '$')"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<para><xsl:value-of select="$text"/></para>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
推荐阅读
- python - 数据框上的python loc问题
- javascript - 带有jQuery加载的onclick事件未触发
- mysql - 在 Rails 中,使用 mysql2 gem 从 MySQL 读取点类型时出现问题
- sql - 数据透视表返回具有 NULL 的多行,未分组在一行上
- ios - 我如何只响应 UI 图像中的触摸?
- excel - Excel VBA - 在用户调整他们的条目后再次检查过滤表并重新验证 - 逻辑上不起作用
- .net - 在 .Net Core API 中将异常和其他错误记录到 txt 文件的最佳方法
- java - JUnit 的 @TestMethodOrder 注释不起作用
- c# - JsonConvert.Deserialize 错误'没有默认构造函数',但有一个
- android - 将应用程序发布到 Google Play 商店时的库许可证