Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
723 views
in Technique[技术] by (71.8m points)

xpath - how to escape single quote in xslt substring function

I tried to substring data with single quote in XSLT:

String : DataFromXML:'12345'

expected Result: 12345

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

Result: '12345'

i tried below code

<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:'')"/>

Error:

String literal was not closed 'DataFromXML:'--->'<---
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The general rules for escaping are:

In 1.0:

  • if you want the attribute delimiter in a string literal, use the XML escape form &quot; or &apos;
  • if you want the string delimiter in a string literal, you're hosed

In 2.0:

  • if you want the attribute delimiter in a string literal, use the XML escape form &quot; or &apos;
  • if you want the string delimiter in a string literal, double it (for example, 'I can''t')

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

Just Browsing Browsing

[6] html - How to create even cell spacing within a

1.4m articles

1.4m replys

5 comments

56.8k users

...