首页 > 解决方案 > XSL 转换 - 使用来自在线资源的 XML

问题描述

我正在尝试使用来自在线 XML 资源的数据更新现有 XML 文件的 XSL 文件。

原始 XML 文件和 XSL 位于 localhost(使用 http)上,而我的在线资源(另一个包含新内容的 XML 文件)位于https://example.com/xml/update.xml

XSL 看起来像这样:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
                          xmlns:gmd="http://www.isotc211.org/2005/gmd"
                          xmlns:gco="http://www.isotc211.org/2005/gco"                      
                 http://schemas.opengis.net/iso/19139/20060504/srv/srv.xsd">

  <xsl:output method="xml" indent="yes"/>

  <!-- Identity template, copies everything as is -->
  <xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>

  <!-- Override for target element -->
  <xsl:template match="gmd:MD_DataIdentification/gmd:citation/gmd:CI_Citation">
    <!-- Copy the element -->
    <xsl:copy>
      <!-- And everything inside it -->
      <xsl:apply-templates select="@*|node()"/>
      <xsl:for-each select="document('https://example.com/xml/update.xml')/newData">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:for-each>
    </xsl:copy>
  </xsl:template>

</xsl:stylesheet>

在 localhost 上查看 XML 文件时出现以下错误: Unsafe attempt to load URL https://example.com/xml/update.xml from frame with URL http://localhost/tutorial/metadata/ENVI_Natura2000.xml. Domains, protocols and ports must match.

有什么办法可以修改我的 XSL 文档来绕过它?

标签: xmlxsltproxy

解决方案


推荐阅读