XSLT firefox uri问题

时间:2011-09-19 12:32:30

标签: xml firefox xslt

我正在使用xml / xsl,我已经实现了一个链接。该链接正在引用另一个xml文件。使用firefox浏览器我无法打开链接。 我一直在网上搜索,发现你必须在链接中添加file://

这对绝对路径非常有效,但是相对路径无法解析链接。

示例代码:

文件夹D中的

file1.xml:/ try

  <?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>
文件夹D中的

layout.xsl:/ try

<?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>
文件夹D:/ try

中的

tt.xml

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

如果将file1.xml中的uri D:/tt.xml替换为相对路径tt.xml,则它正在运行。

我想要一个将uri转换为可接受格式的函数。

此致 Marky

1 个答案:

答案 0 :(得分: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>

但我认为这不是最佳解决方案。

相关问题