0

I am trying to figure out how to ignore ' ' in the locator while writing xpath.

For example:

//affiliation-summary[@ng-if='oaProfileStatus.oa.workflowState === 'PENDING_CONFIRMATION''] 

Now what I am trying to do is ignore ' before P and ' after N in pending and confirmation respectively so that Xpath don't treat these as start and end point of identifier.

Just to be full proof if what I am trying to achieve is not clear yet then this is what we do in java

System.out.println("\"Hello");

to ignore " from terminating the String so that "Hello will be printed.

How can I achieve this in Xpath?

SelThroughJava
  • 321
  • 3
  • 14

1 Answers1

0

In XPath 1.0 you can put ' in a string by using " as the string delimiter or vice versa. When the XPath is nested in an XML document (e.g. XSLT, XSD, or XProc), you may also need to escape this as an XML character reference, or when XPath is nested in a Java/C# string you may need to escape it as \' or \"

In XPath 2.0 there is an additional option: for a string delimited by single quotes you can include a doubled single quote ('Don''t do it!'), and for a string delimited by double quotes you can include a doubled double quote ("Don't say ""I can't""").

A useful trick for XPath-within-XSLT, especially with 1.0, is to use variables, for example

<xsl:variable name="quot">"</xsl:variable>
<xsl:variable name="apos">'</xsl:variable>
<xsl:variable name="sentence" 
 select="concat('Don', $apos, 't say ', $quot, 'I can', $apos, 't', $quot)"/>
Michael Kay
  • 156,231
  • 11
  • 92
  • 164