2014-06-13 46 views
-3

在當天的匆忙和沮喪中,我並沒有明顯發佈足夠的相關信息,因此讓我重新解釋一下這個問題。謝謝你的耐心。卡住轉義字符的使用

我有一些XML所返回以下標籤:

etc... 
<tr> 
      <td class="Label Center">22</td> 
      <td Indentation="4" class="Label Stub Left">Listings</td> 
<tr> 
    <td class="Label Center">23</td> 
    <td Indentation="6" class="Label Stub Left">Notes&lt;sup&gt;1&lt;/sup&gt;</td> 
</tr> 
etc... 

我處理它們下面的方式,一切都很好,除了一兩件事:

<?xml version="1.0" encoding="utf-8"?> 
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
<xsl:output method="html" encoding="utf-8"/> 
<xsl:param name="TABLENUM"/> 

<xsl:template match="/"> 
<xsl:for-each select="/Response/MakeStory/div/div[@class='Table'][$TABLENUM]"> 
    <h3 style="margin:2px; padding:0;"><xsl:value-of select="div [@class='TableTitle']"/></h3> 
    <h4 style="margin:2px; padding:0;"><em><xsl:value-of select="div[@class='TableSubTitle']"/></em></h4> 
    <xsl:for-each select="div[@class='HtmlTable']/table"> 
     <table cellpadding="3" cellspacing="0"> 
          <xsl:copy-of select="thead"/> 
          <xsl:apply-templates select="tbody"/> 
     </table> 
    </xsl:for-each> 
</xsl:for-each> 
</xsl:template> 


<xsl:template match="tbody"> 
    <xsl:copy> 
    <xsl:apply-templates select="tr"/> 
    </xsl:copy> 
</xsl:template> 

<xsl:template match="tr"> 
    <xsl:copy> 
     <xsl:apply-templates select="td"/> 
    </xsl:copy> 
</xsl:template> 

<xsl:template match="td[contains(@class, 'Left')]"> 
    <td align="left" style="padding-left: {@Indentation * 3}px;"> 
     <xsl:copy-of select="node()"/>    
    </td> 
</xsl:template> 

<xsl:template match="td[contains(@class, 'Center')]"> 
    <td align="center"> 
    <xsl:copy-of select="node()" /> 
    </td> 
</xsl:template> 

我的問題,其與上面的例子一樣,當輸出項目時,轉義標籤被視爲文字並且從字面上寫出註釋,而不是像t那樣上標數字他的筆記。

我已經嘗試了很多方法,其中包括,xsl文本轉義字符設置爲不包裹節點,試圖應用模板而不是使用複製選擇節點選項與選擇條件查找轉義字符,但我很遺憾沒有任何運氣。

什麼是最好的方法來處理這個問題。我確信這非常簡單,但是我對XSLT的有限瞭解還沒有真正完成。任何信息,將不勝感激。

哦,我想「我有XSLT 2,但我不確定。

謝謝。

+5

不是很清楚,我很害怕。嘗試給出一個你的輸入和期望輸出的例子:希望能夠清理一些事情。 –

+1

同上:你沒有告訴我們你想要發生什麼(預期產出),也沒有告訴我們實際發生了什麼(實際產出)。 – LarsH

+0

該問題已經通過更多相關信息進行了修訂。謝謝你的時間。 – EXL

回答

2

的示例儘量減少這個問題,讓我們來看看下面的XML源:

<tr> 
    <td>Notes&lt;sup&gt;1&lt;/sup&gt;</td> 
</tr> 

以下樣式:

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

<xsl:template match="tr"> 
    <tr> 
     <xsl:apply-templates select="td"/> 
    </tr> 
</xsl:template> 

<xsl:template match="td"> 
    <td> 
     <xsl:value-of select="." disable-output-escaping="yes"/> 
    </td> 
</xsl:template> 

</xsl:stylesheet> 

將返回:

<?xml version="1.0" encoding="UTF-8"?> 
<tr> 
    <td>Notes<sup>1</sup></td> 
</tr> 

這在HTML將呈現爲:

enter image description here