【问题标题】:XSL transformation error - Namespace prefix is not definedXSL 转换错误 - 未定义命名空间前缀
【发布时间】:2019-07-01 12:42:03
【问题描述】:

我正在尝试使用 XSL 转换来转换此 XML 文件:https://gist.github.com/mleontenko/d83026d2a02bedeb7531881144e345aa

我正在使用 XSL 文件将新的 XML sn-p 添加到现有代码中。 XSL 文件如下所示:

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

  <!-- 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:CI_Citation">
    <!-- Copy the element -->
    <xsl:copy>
      <!-- And everything inside it -->
      <xsl:apply-templates select="@* | *"/> 
      <!-- Add new node (or whatever else you wanna do) -->
      <!-- <xsl:element name="newNode"/> -->
      <gmd:identifier>
          <gmd:RS_Identifier>
             <gmd:code>
                <gco:CharacterString>0105</gco:CharacterString>
             </gmd:code>
             <gmd:codeSpace>
                <gco:CharacterString>hr:nipp:hr</gco:CharacterString>
             </gmd:codeSpace>
             <gmd:version>
                <gco:CharacterString>1.0</gco:CharacterString>
             </gmd:version>
          </gmd:RS_Identifier>
       </gmd:identifier>
    </xsl:copy>
  </xsl:template>

</xsl:stylesheet>

我在浏览器中收到以下错误(未定义 [element] 上的命名空间前缀 [prefix]):

我该如何解决这个问题?

【问题讨论】:

  • 您只需在样式表中添加xmlns:gmd="http://www.isotc211.org/2005/gmd"xmlns:gco="http://www.isotc211.org/2005/gco"(在&lt;xsl:stylesheet&gt;标签中)
  • 成功了,谢谢!如果您希望它被接受,请随意添加答案。

标签: xml xslt xsl-stylesheet


【解决方案1】:

消息告诉您名称空间前缀尚未定义。这是指出现在 XSLT 中的 gmd:gco: 前缀。

它们是在您的 XML 中定义的......

<gmd:MD_Metadata xmlns:gmd="http://www.isotc211.org/2005/gmd" 
                 xmlns:gco="http://www.isotc211.org/2005/gco"

因此,您只需向 XSLT 添加类似的定义,它就可以识别它们

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多