Solution for rendering xml special characters in xslt output. Xslt compilation failure: Unescaped & or nonterminated character/entity reference at line 343

Ever tried an xslt transformation and run into Xslt compilation failure: Unescaped & or nonterminated character/entity reference at line xxx: This happens because the xsl transformation contains special characters such as "&". If your intent is just to output "&" using the xsl, you would need to use CDATA to accomplish this. One way is to define a variable as below:

    <xsl:variable name="and"></xsl:variable>
And then you would use this variable as needed.  For example, if you wanted below output which is a URL with special character such as "&" in it:
    <trackingurl>
        http://www.mysite.com/index.jsp?carrier=usps&mode=1day&trackingId=10
    </trackingurl>
, then you would write the xsl as below:
    <xsl:variable name="trackingBaseUrl">
        http://www.mysite.com/index.jsp?
    <xsl:variable></xsl:variable>
    <xsl:variable name="mode" select="ShippingMethod"></xsl:variable>
        <xsl:variable name="carrier" select="CarrierServiceCode"></xsl:variable>
    <xsl:variable name="and"></xsl:variable>
    <trackingurl>
        <xsl:value-of select="concat($trackingBaseUrl, '?carrier=', $carrier, $and, 'mode=', $mode, $and, 'trackingId=', TrackingNumber)" disable-output-escaping="yes"/>
    </trackingurl>
Doing the above will provide the required output for you.