2011-09-19 62 views
1

我正在使用xml/xsl,並且已經實現了一個鏈接。該鏈接正在引用另一個xml文件。隨着Firefox瀏覽器,我無法打開鏈接。 我一直在網上搜索,發現你必須添加file://到鏈接。XSLT firefox uri問題

這對於絕對路徑非常有效,但相對路徑無法解析鏈接。

例如代碼:

file1.xml在目錄d:/嘗試在目錄d

<?xml version="1.0" encoding="UTF-8"?> 
    <?xml-stylesheet type="text/xsl" href="file:///D:/try/layout.xsl"?> 
    <s1> 
    <s> 
     <uri>D:/tt.xml</uri> 
    </s> 
    </s1> 

layout.xsl:/嘗試在

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

    <xsl:output method="html" indent="yes" encoding="UTF-8"/> 

    <xsl:template match="/"> 
    <html> 
     <xsl:element name="body"> 
      <xsl:apply-templates select="s1"/> 
     </xsl:element> 
    </html> 
    </xsl:template> 


    <xsl:template match="s1"> 
    <xsl:apply-templates select="s"/> 
    </xsl:template> 

    <xsl:template match="s"> 
    <table> 
     <tr><th>Uri: </th><td> 
     <xsl:element name="a"> 
      <xsl:attribute name="href"><xsl:value-of select="uri"/></xsl:attribute> 
      <div><xsl:value-of select="uri"/></div> 
     </xsl:element> 
     </td></tr> 
    </table> 
    </xsl:template> 

</xsl:stylesheet> 

tt.xml文件夾D:/ try

<?xml version="1.0" encoding="UTF-8"?> 
<s1> 
    <s> 
    <h1>HELLO</h1> 
    </s> 
</s1> 

如果使用相對路徑tt.xml替換file1.xml中的uri D:/tt.xml,它正在工作。

我想有一個函數將uri轉換爲可接受的格式。

問候, Marky

+0

我不明白是什麼問題。考慮將一些代碼或URL發佈到顯示問題的測試案例中。 'resolve-uri'不是XSLT 1.0的一部分,當前瀏覽器支持的XSLT版本並不期望該功能可以在Firefox或其他瀏覽器中使用。 –

+0

編輯,見上文。 – Mark

+0

你能舉一個應該可以工作但不工作的XML的例子嗎? –

回答

0

同時,我得到這個:

 <xsl:if test="regexp:match(uri, '^.[^:].*', 'g')"> 
      <xsl:element name="a"> 
      <xsl:attribute name="href"><xsl:value-of select="uri"/></xsl:attribute> 
      <div><xsl:value-of select="uri"/></div> 
      </xsl:element> 
     </xsl:if> 
     <xsl:if test="regexp:match(uri, '.*:.*', 'g')"> 
      <xsl:element name="a"> 
      <xsl:attribute name="href"><xsl:value-of select="concat('file://',uri)"/>   
      </xsl:attribute> 
      <div><xsl:value-of select="uri"/></div> 
      </xsl:element> 
     </xsl:if> 

但我不認爲這是最好的解決辦法。