1

I have troubles with xslt transformation where the original xml doesn't have escaped characters like doublequote.

I am testing with xsltproc but I didn't manage to handle proper result. I searched for a solution a lot but it seems that I cannot find the right solution for my issue. Any help would be appreciated.

Source xml:

<test>abc"abc"</test>

xslt:

<xsl:stylesheet 
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
        xmlns:xs="http://www.w3.org/2001/XMLSchema" version="1.0">
    <xsl:template match="/">
        &lt;test2 property=&quot;<xsl:value-of select="./test"/>&quot; /&gt;
    </xsl:template>
</xsl:stylesheet>

Result I get:

<?xml version="1.0"?>
        &lt;test2 property="abc"abc"" /&gt;

Result I need:

<?xml version="1.0"?>
    &lt;test2 property="abc&quot;abc&quot;" /&gt;

Verbose output:

xsltProcessOneNode: applying template '/' for /
xsltApplySequenceConstructor: copy text 
        <test2 property="
xsltCopyText: copy text 
        <test2 property="
xsltValueOf: select ./test
xsltCopyTextString: copy text abc"abc"
xsltValueOf: result 'abc"abc"'
xsltApplySequenceConstructor: copy text " />

xsltCopyText: copy text " />

freeing transformation dictionary
freeing dictionary from stylesheet

Thanks for help!

EDIT

New findings: If I add & sign, it is correctly escaped into & but " is not. I thought that it should be escaped as well, based on what I read on the internet.

Gavilan Comun
  • 1,361
  • 2
  • 11
  • 19
Matjaz
  • 468
  • 5
  • 21
  • 1
    Is the expected output in your question totally correct? Shouldn't it be `<test2 property="abc"abc"" />`? – Tim C Apr 13 '15 at 12:25
  • If it's supposed to be escaped markup then it would actually need to be `<test2 property="abc&quot;abc&quot;" />` with the double-quotes escaped twice so they end up as `"` after one round of un-escaping. – Ian Roberts Apr 13 '15 at 13:38

0 Answers0