2014-01-21 158 views
0

我正在使用XSLT将XML转换为HTML。将XML转换为HTML

我有以下XML结构:

<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> 

我的XSLT是如下

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

tansformation HTML后是

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

我这里想要什么,在原有的风格XML在转换后应用。

回答

0

你想要的是类似下面

<?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> 

第一个模板复制所有节点上,第二个模板确实改造所需输出,而第三模板消除了Info节点。

+0

我现在能够正确地改变它。但是我在使用模板时遇到了一个新问题。每当有& nbsp;在描述中显示为  有什么办法来处理这个? –

+0

尝试通过Mads Hansen查看此解决方案(http://stackoverflow.com/questions/21272212/xslt-1-0-cant-translate-apostrophe) –

0

而不是

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

尝试:

<xsl:copy-of select="Info/Description/node()"/>