title: XSLT XML to JSON and Escape Double Quote
body: <p>I'm using the following XSLT to convert XML to JSON:
  <a href="https://github.com/bojanbjelic/xml2json/blob/master/xml2json.xsl" rel="nofollow noreferrer">https://github.com/bojanbjelic/xml2json/blob/master/xml2json.xsl</a></p>
  
  <p>It's working great but I would really like to extend it so that any double quotes within the XML values are escaped in the JSON output:</p>
  
  <pre><code>&lt;tag&gt;This is "my" test&lt;/tag&gt;
  </code></pre>
  
  <p>To become:</p>
  
  <pre><code>{
      "tag": "This is \"my\" test"
  }
  </code></pre>
  
  <p>There's some good code here: <a href="https://stackoverflow.com/questions/9370633/xslt-replacing-double-quotes-with-escape-sequence">XSLT + Replacing double quotes with escape sequence</a>.</p>
  
  <pre><code>&lt;xsl:template name="escapeQuote"&gt;
    &lt;xsl:param name="pText" select="."/&gt;
    &lt;xsl:if test="string-length($pText) &gt;0"&gt;
     &lt;xsl:value-of select="substring-before(concat($pText, '&amp;quot;'), '&amp;quot;')"/&gt;
     &lt;xsl:if test="contains($pText, '&amp;quot;')"&gt;
      &lt;xsl:text&gt;\"&lt;/xsl:text&gt;
      &lt;xsl:call-template name="escapeQuote"&gt;
        &lt;xsl:with-param name="pText" select="substring-after($pText, '&amp;quot;')"/&gt;
      &lt;/xsl:call-template&gt;
     &lt;/xsl:if&gt;
    &lt;/xsl:if&gt;
  &lt;/xsl:template&gt;
  </code></pre>
  
  <p>But unfortunately I'm not experienced enough with XSLTs to integrate it with what the code I'm using from above. Any help would be much appreciated.</p>