0

I am transforming XML into HTML using XSLT.

I have the following XML structure:

<Info><Description>
<p><strong><span style="font-family: Verdana; color: #f0b444;">Description<br />
<span class="BookingResultTxtBlue">description goes here.</span></span></strong></p>

<p><strong><span style="font-family: Verdana; color: #f0b444;"><span class="BookingResultTxtBlue">Test 1</span></span></strong></p>

<p><strong><span style="font-family: Verdana; color: #f0b444;"><span class="BookingResultTxtBlue">Test 2</span></span></strong></p>

<p><strong><span style="font-family: Verdana; color: #f0b444;"><span class="BookingResultTxtBlue">Test 3</span></span></strong></p>

</Description></Info>

My XSLT is as follows

<table>
 <tr>
      <td>
       <xsl:value-of  select='Info/Description'/>
     </td>
</tr>
</table>

After tansformation html is

<table>
 <tr> 
   <td>description goes here
       Test1
       Test2
       Test3
   </td>
 </tr>
</table>

What i want here is, styles in original XML to be applied after transformation.

Mandar Patil
  • 538
  • 2
  • 10
  • 29

2 Answers2

0

What you want is something like below

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">

    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="Info/Description">
        <table>
            <tr>
                <td Class="BookingResultTxtBlue">
                    <xsl:apply-templates/>
                </td>
            </tr>
        </table>
    </xsl:template>

    <xsl:template match="Info">
        <xsl:apply-templates/>
    </xsl:template>
</xsl:stylesheet>

The first template copies all nodes, the second template does the transformation to your desired output, and the third template eliminates the Info node.

Joel M. Lamsen
  • 7,143
  • 1
  • 12
  • 14
  • I am able to transform it correctly now. But i am facing a new problem while using template. Whenever there is &nbsp; in description it is getting displayed as   Is there any way to handle this? – Mandar Patil Jan 22 '14 at 04:22
  • Try to see this solution by Mads Hansen (http://stackoverflow.com/questions/21272212/xslt-1-0-cant-translate-apostrophe) – Joel M. Lamsen Jan 22 '14 at 05:25
0

Instead of

<xsl:value-of  select='Info/Description'/>

try:

<xsl:copy-of select="Info/Description/node()"/>
michael.hor257k
  • 113,275
  • 6
  • 33
  • 51