Loading ...
Sorry, an error occurred while loading the content.

Re: [dita-users] escape special characters in xsl:if

Expand Messages
  • Steven Calderwood
    XPath 2.0 allows you to escape the single quote with a second single quote (so you have four single quotes in your contains):
    Message 1 of 4 , Apr 5 5:18 AM
    • 0 Attachment
      XPath 2.0 allows you to escape the single quote with a second single quote (so you have four single quotes in your contains):
      <xsl:if test=".//*[$excludes]/text()[contains(.,'''')]">

      Same thing goes for escaping double quote marks.

      Note that Mathias' solution to use a variable can make the code easier to read, which is a big plus. 

      Steven

      -- 

      Steven Calderwood

      Content Management Engineer

      Human Kinetics

      217-351-5076 ext. 7830

      Direct Line: 217-403-7830

      stevenc@...



      From: Leigh White <lwwhite5@...>
      Reply-To: "dita-users@yahoogroups.com" <dita-users@yahoogroups.com>
      Date: Friday, April 5, 2013 3:03 AM
      To: "dita-users@yahoogroups.com" <dita-users@yahoogroups.com>
      Subject: [dita-users] escape special characters in xsl:if

       

      This is a basic XPath question, but it pertains to the QA plugin, so maybe I can squeeze it in here. I am trying to search for occurrences of single quotes in my content. I've searched all over the Web and have tried the following:

      <xsl:if test=".//*[$excludes]/text()[contains(.,'&quot;')]">
      <xsl:if test=".//*[$excludes]/text()[contains(.,'\'')]">
      <xsl:if test=".//*[$excludes]/text()[contains(.,'&#39;')]">
      <xsl:if test=".//*[$excludes]/text()[contains(.,'"'"')]">

      None of them are valid. So how in the heck do you escape special characters in an XPath expression?

      Thanks!
      Leigh

    • Leigh White
      Thank you, Steven! Using a single quote to escape was the one thing I didn t think of. Leigh
      Message 2 of 4 , Apr 5 11:10 AM
      • 0 Attachment
        Thank you, Steven! Using a single quote to escape was the one thing I didn't think of.
        Leigh

        --- In dita-users@yahoogroups.com, Steven Calderwood <stevenc@...> wrote:
        >
        > XPath 2.0 allows you to escape the single quote with a second single quote (so you have four single quotes in your contains):
        > <xsl:if test=".//*[$excludes]/text()[contains(.,'''')]">
        >
        > Same thing goes for escaping double quote marks.
        >
        > Note that Mathias' solution to use a variable can make the code easier to read, which is a big plus.
        >
        > Steven
        >
        > --
        > Steven Calderwood
        > Content Management Engineer
        > Human Kinetics
        > 217-351-5076 ext. 7830
        > Direct Line: 217-403-7830
        > stevenc@...<mailto:stevenc@...>
        >
        >
        > From: Leigh White <lwwhite5@...<mailto:lwwhite5@...>>
        > Reply-To: "dita-users@yahoogroups.com<mailto:dita-users@yahoogroups.com>" <dita-users@yahoogroups.com<mailto:dita-users@yahoogroups.com>>
        > Date: Friday, April 5, 2013 3:03 AM
        > To: "dita-users@yahoogroups.com<mailto:dita-users@yahoogroups.com>" <dita-users@yahoogroups.com<mailto:dita-users@yahoogroups.com>>
        > Subject: [dita-users] escape special characters in xsl:if
        >
        >
        >
        > This is a basic XPath question, but it pertains to the QA plugin, so maybe I can squeeze it in here. I am trying to search for occurrences of single quotes in my content. I've searched all over the Web and have tried the following:
        >
        > <xsl:if test=".//*[$excludes]/text()[contains(.,'"')]">
        > <xsl:if test=".//*[$excludes]/text()[contains(.,'\'')]">
        > <xsl:if test=".//*[$excludes]/text()[contains(.,''')]">
        > <xsl:if test=".//*[$excludes]/text()[contains(.,'"'"')]">
        >
        > None of them are valid. So how in the heck do you escape special characters in an XPath expression?
        >
        > Thanks!
        > Leigh
        >
      Your message has been successfully submitted and would be delivered to recipients shortly.