Created
October 30, 2014 17:28
-
-
Save fidothe/9da736aadee12629f5df to your computer and use it in GitHub Desktop.
escaping double quotes in XSLT
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
\hi\ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
\"hi\" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<r>"hi"</r> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" | |
xmlns:xs="http://www.w3.org/2001/XMLSchema" | |
exclude-result-prefixes="xs" | |
version="1.0"> | |
<xsl:output media-type="text/plain" omit-xml-declaration="yes"/> | |
<xsl:template name="encode-string"> | |
<xsl:param name="s" select="''"/> | |
<xsl:value-of select="translate($s, '"', '\"')"/> | |
</xsl:template> | |
<xsl:template match="/"> | |
<xsl:call-template name="encode-string"><xsl:with-param name="s" select="*"/></xsl:call-template> | |
</xsl:template> | |
</xsl:stylesheet> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Because
translate()
doesn't do what you think it does :-)What you want is
replace()
but if you're determined to do it with XSLT 1.0, you have to roll that one by hand:So much easier if you can use XSLT 2.0:
Hope that helps...