XSLT document() usage with WebKit browsers

后端 未结 2 1975
一整个雨季
一整个雨季 2021-01-13 21:36

I\'m having an issue when attempting to include and access multiple XML documents in an XSL stylesheet. I\'m assigning document nodes as variables and then attempting to acc

相关标签:
2条回答
  • 2021-01-13 22:11

    Chrome has a cross-origin-policy that prevents includes of local files. The document function can only reference itself locally:

    <?xml version="1.0" encoding="utf-8"?>
    <?xml-stylesheet type="text/xsl" href="pitarget.xml"?>
    <xsl:stylesheet version="1.0"
                    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml"
                    >
    <xsl:variable name="gal" select="'howdy'"/>
    <?var gal?><!--howdy-->
    <?echo gal?>
    <?html5 ?>
    
    <xsl:output method="html" encoding="utf-8" version="" indent="yes" standalone="no" media-type="text/html" omit-xml-declaration="no" doctype-system="about:legacy-compat" />
    
    <xsl:template match="xsl:stylesheet">
      <xsl:apply-templates select="processing-instruction()"/>
    </xsl:template>
    
    <xsl:template match="/">
      <xsl:value-of select="processing-instruction('html5')"/>
      <html>
        <head>
          <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
        </head>
        <body>
          <xsl:apply-templates/>
        </body>
      </html>
    </xsl:template>
    
    
    <xsl:template match="processing-instruction('echo')">
      <xsl:value-of select="//xsl:variable/@select[../@name=current()]"/>
      <xsl:value-of select="count(document('pitarget.xml')//*) - 1"/>
    </xsl:template>
    
    <xsl:template match="processing-instruction('var')">
      <xsl:processing-instruction name="{.}">
        <xsl:value-of select="."/>
        <xsl:value-of select="./following-sibling::node()"/>
      </xsl:processing-instruction>
    </xsl:template>
    
    </xsl:stylesheet>
    
    0 讨论(0)
  • 2021-01-13 22:22

    Google have decided that allowing the .xml file to read the .xlst file off a file:// URL is a security hole and they have blocked it.

    The chrome.exe command line option --allow-file-access-from-files will circumvent this safeguard.

    0 讨论(0)
提交回复
热议问题