如何在xslt子字符串函数中转义单引号 [英] how to escape single quote in xslt substring function

查看:29
本文介绍了如何在xslt子字符串函数中转义单引号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在 XSLT 中用单引号对数据进行子串:

I tried to substring data with single quote in XSLT:

String : DataFromXML:'12345'

预期结果:12345

<xsl:value-of select="substring-after('$datafromxml','DataFromXML:')"/>

结果:'12345'

我试过下面的代码

<xsl:value-of select="substring-after('$datafromxml','DataFromXML:&#39;')"/>

<xsl:value-of select="substring-after('$datafromxml','DataFromXML:&apos;')"/>

<xsl:value-of select="substring-after('$datafromxml','DataFromXML:'')"/>

错误:

String literal was not closed 'DataFromXML:'--->'<---

推荐答案

转义的一般规则是:

在 1.0 中:

  • 如果您想在字符串文字中使用属性定界符,请使用 XML转义形式 &quot;&apos;
  • 如果你想在字符串文字中使用字符串分隔符,你就完了

在 2.0 中:

  • 如果您想在字符串文字中使用属性定界符,请使用 XML转义形式 &quot;&apos;
  • 如果您想在字符串文字中使用字符串分隔符,请将其加倍(对于例如,我不能")

使用 Vitaliy 所示的变量 $quot 或 $apos 可以使代码更加清晰.

The use of a variable $quot or $apos as shown by Vitaliy can make the code much clearer.

这篇关于如何在xslt子字符串函数中转义单引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆