2008-12-29 87 views
1

我在我所存儲的一些HTML下的評論這樣XSLT轉換問題與禁用輸出轉義

<root> 
    <node> 
    <!-- 
      <a href="mailto:[email protected]"> Mail me </a> 
     --> 
</node> 
</root> 
現在

在我的轉換XSLT礦我給它指向節點的XPathNavigator的代碼和XML在xslt我傳遞的評論值作爲參數。

假設$ HREF是<a href="mailto:[email protected]"> Mail me </a>

在XSLT我做<xsl:value-of select="$href" disable-output-escaping="yes">

但$ href是仍然逃脫XSLT轉換的結果來了< >

是否有任何人知道什麼是錯在這方面任何幫助都會非常敏感。

感謝 問候 Azeem

回答

2

當節點失去其特殊含義註釋的一部分 - 這樣的「href」不是一個節點,所以你不能用它來選擇的東西。

可以這樣選擇的意見:

<xsl:template match="/"> 
<xsl:value-of select="/root/node/comment()" disable-output-escaping="yes"/> 
</xsl:template> 

這將產生基於你的XML輸入:

cristi:tmp diciu$ xsltproc test.xsl test.xml 
<?xml version="1.0"?> 

     <a href="mailto:[email protected]"> Mail me </a> 
-1

我也試了一下你剛剛說的話沒有工作,我現在用的是XML是

<?xml version="1.0" ?> 
    <root> 
    <institution id="1"> 
     <data> 
     <ahrefmail> 
      <!-- 
     <a href='mailto:[email protected]' class='text'></a> 
      --> 
     </ahrefmail> 

     <mail> 
      [email protected] 
     </mail> 
     </data> 
    </institution> 


    <institution id="2"> 
     <data> 
     <ahrefmail> 
      <!-- 
     <a href='mailto:[email protected]' class='text'></a> 
     --> 
     </ahrefmail> 

     <mail> 
      [email protected] 
     </mail> 
     </data> 
    </institution> 

</root> 

在XSLT我做

其中$ ID作爲參數傳遞== 1 的ahrefmail節點仍然與LT & GT逃脫

感謝 問候 Azeem

+0

的XSLT代碼丟失... – bortzmeyer 2009-01-05 13:21:40

1

如diciu提到的,一旦評論文本內不再XML -parsed。

該問題的一個解決方案是使用雙通道方法。一次通過取出註釋<a href=""></a>節點並將其放入正常的XML中,然後第二次通過所需輸出來豐富數據:<a href="">Your Text Here</a>

第二種單通方法是通過正則表達式(或者在我們的例子中只是從XML中提取)從註釋中提取需要的文本(本例中爲電子郵件地址),然後創建標記需要在它周圍。

<xsl:template match="ahrefmail/comment()"> 
    <xsl:element name="a"> 
     <xsl:attribute name="href" select="../../mail"/> 
     <xsl:attribute name="class" select="'text'"/> 
     <xsl:text>Mail Me!</xsl:text> 
    </xsl:element> 
</xsl:template> 

這裏假設你已經有一個identity template到位