Reputation: 35
I have below sample xml `
<?xml version="1.0" encoding="utf-8"?>
<TDX>
<AddressData>
<AddressDetail>
<Address FieldName="ReceiverAddress1" FieldValue="CNR TOORONG & TOORAK RD"/>
</AddressDetail>
</AddressData>
</TDX>
And the XSLT that transforms this xml into desired format. I have taken a single node here
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml"/>
<xsl:template match="/">
<ConNotes>
<ConNote>
<ReceiverAddress1>
<xsl:value-of disable-output-escaping="yes" select="TDX/AddressData/AddressDetail/Address[@FieldName='ReceiverAddress1']/@FieldValue"/>
</ReceiverAddress1>
</ConNote>
</ConNotes>
</xsl:template>
</xsl:stylesheet>
Whenever I try to transform the XML using xslt I get the error "Whitespace is not allowed at this location". I have figured it out that this error is due to the special character & present in the FieldValue attribute of address node.
I have tried disable-output-escpaing="yes" but it's not working as expected.
I have used "output method="xml"" in the XSLT file.
Please help me with this. I am using XML notepad for applying the transformation.
I am expecting the output xml like this:
<?xml version="1.0" encoding="utf-8" ?>
- <ConNotes>
- <ConNote>
<ReceiverAddress1>CNR TOORONG & TOORAK RD</ReceiverAddress1>
</ConNote>
</ConNotes>
Upvotes: 0
Views: 1246
Reputation: 32980
When you use disable-output-escaping="yes"
then the ampersand &
in the output is not escaped as entity &
. The output is then not a well-formed XML document. When you open the result XML in IE you will get the "Whitespace..." error.
The fix is trivial: Just remove the disable-output-escaping="yes"
and
the output will be well-formed:
<ConNotes>
<ConNote>
<ReceiverAddress1>CNR TOORONG & TOORAK RD</ReceiverAddress1>
</ConNote>
</ConNotes>
Upvotes: 1