开发者

XSLT firefox uri issue

I am working with xml/xsl and I've implemented a link. The link is referencing another xml file. With the firefox browser I'm unable to open the link. I've been searching on the net and found that you've got to add file:// to the link.

That is working really well for absolute paths, but with relative paths it is not able to resolve the link.

Example Code:

file1.xml in the folder D:/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>

layout.xsl in the folder D:/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>

tt.xml in the folder D:/try

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

If you replace the uri D:/tt.xml in file1.xml with the relative path tt.xml it is working.

I'd like to have a function that converts the uri to an acceptable format.

Regards, Marky


Meanwhile I got this:

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

But I don't think that's the best solution.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜