XSL 转换错误 - 命名空间前缀未定义
XSL transformation error - Namespace prefix is not defined
我正在尝试使用 XSL 转换来转换此 XML 文件:https://gist.github.com/mleontenko/d83026d2a02bedeb7531881144e345aa
我正在使用 XSL 文件向现有代码添加新的 XML 片段。 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]):
我该如何解决这个问题?
该消息告诉您命名空间前缀尚未定义。这是指 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">
我正在尝试使用 XSL 转换来转换此 XML 文件:https://gist.github.com/mleontenko/d83026d2a02bedeb7531881144e345aa
我正在使用 XSL 文件向现有代码添加新的 XML 片段。 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]):
我该如何解决这个问题?
该消息告诉您命名空间前缀尚未定义。这是指 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">