I have a xslt stylesheet to process some XML data, provided by a legacy system. XML Sample:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<contract>
<variable id="info">
<variable id="client">
<variable id="profession" value="0128"/>
<variable id="missingInfo" value="null"/>
<variable id="address">
<variable id="town" value="MADRID"/>
<variable id="street" value="CALLE SAN SEBASTIAN"/>
<variable id="postalCode" value="50505-207"/>
</variable>
<variable id="taxId" value="123456789"/>
<variable id="declineDetails" value="null"/>
</variable>
<variable id="height" value="null"/>
</variable>
<variable id="supplier">
<variable id="phoneNumber" value="1020304050"/>
<variable id="address">
<variable id="town" value="BARCELONA"/>
<variable id="street" value="AVINGUDA DIAGONAL 44"/>
<variable id="postalCode" value="40780-575"/>
</variable>
<variable id="taxId" value="1020304050"/>
<variable id="name" value="STICKS & STONES"/>
<variable id="birthDate" value="null"/>
<variable id="email" value="sticksandstones@beemail.org"/>
</variable>
</contract>
XSL stylesheet in use (simplified):
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<result>
<xsl:for-each select="/contract/variable[@id = 'info']/variable[@id = 'client' and variable[@id = 'taxId']/@value != ../variable[@id = 'supplier']/variable[@id = 'taxId']/@value]">
<xsl:variable name="taxId" select="variable[@id = 'taxId']/@value"/>
<contract>
<variable id="info">
<xsl:copy-of select="/contract/variable[@id = 'info']/variable[@id = 'client' and variable[@id = 'taxId']/@value = $taxId]"/>
<xsl:copy-of select="/contract/variable[@id = 'info']/variable[@id != 'client']"/>
</variable>
<xsl:copy-of select="/contract/variable[@id != 'info']"/>
</contract>
</xsl:for-each>
</result>
</xsl:template>
</xsl:stylesheet>
When the stylesheet is applied, there's an exception:
Caused by: net.sf.saxon.trans.XPathException: No closing ';' found for entity or character reference
I tried to process the same data, changing %∓ to a letter (let's say E), everything works as expected. Example:
<variable id="name" value="STICKS E STONES"/>
I also tried to use disable-output-escaping, but without luck, as it seems that is only compatible with xsl:value-of instructions, and not xsl:copy-of instructions.
All the transformations without the ampersand sign work as expected.
What I'm trying to achieve:
<variable id="name" value="STICKS & STONES"/>
How can I keep the ampersand in the final transformed xml?