Handle special character in XSLT

The combination of xml and XSLT is great. I personally like to use it in all my projects . Its working great . Use of xslt helps to reduce development and time and super in maintainability .

In general screnario, we have a xml document which has some node and value . We write a xslt to transform it into some other format (xml,html ). This works great till the time it does not meet the real devil..

 I  have written a simple xslt for it

<?xml version=”1.0″ encoding=”UTF-8″?>

<xsl:stylesheet version=”1.0″ xmlns:xsl=”http://www.w3.org/1999/XSL/Transform“>
<xsl:output method=”html”/>
<xsl:template match=”/”>
    <table border=”1″>
      <tr bgcolor=”Blue”>
        <th>Company Name</th>
      <xsl:for-each select=”catalog/Rec”>
         <xsl:value-of select=”CompanyName”/>


and I have a simple below mentioned xml

<?xml version=”1.0″ encoding=”utf-8″?>

  <CompanyName>A B</CompanyName>
  <CompanyName>C & D</CompanyName>

Now if we run this transformation by addingxml-stylesheet type=”text/xsl” href=”test.xslt”?>

This will crash my xslt .


Replace CompanyName  tas as   < ! [ CDATA[ C &D ]]>

Thats it !!


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s