gpt4 book ai didi

xml - 如何修复 : Attribute xmlns:gco redefined

转载 作者:行者123 更新时间:2023-12-04 17:01:41 25 4
gpt4 key购买 nike

我正在使用 XSLT 更新一些旧的 XML 元数据,我意识到目标输出具有以下命名空间:

xmlns:gco="http://standards.iso.org/iso/19115/-3/gco/1.0"

旧元数据具有以下命名空间:
xmlns:gco="http://www.isotc211.org/2005/gco

如果我将两者都放在 XSLT 的标题中,则会出现错误
属性 xmlns:gco 重新定义

我试图删除其中之一,但 XSLT 无法提取正确的值,我得到了空字符串:
xsltApplySequenceConstructor: copy node identificationInfo
xsltApplySequenceConstructor: copy node MD_DataIdentification
xsltApplySequenceConstructor: copy node citation
xsltApplySequenceConstructor: copy node CI_Citation
xsltApplySequenceConstructor: copy node title
xsltApplySequenceConstructor: copy node CharacterString
xsltValueOf: select //gmd:identificationInfo/gmd:MD_DataIdentification/gmd:citation/gmd:CI_Citation/gmd:title/gco:CharacterString
xsltValueOf: result ''

这是 XML 输入文件的一部分
<?xml version="1.0" encoding="UTF-8"?>
<gmi:MI_Metadata xmlns:gmd="http://www.isotc211.org/2005/gmd" xmlns:safe="http://www.esa.int/safe/sentinel-1.0" xmlns:gss="http://www.isotc211.org/2005/gss" xmlns:s1="http://www.esa.int/safe/sentinel-1.0/sentinel-1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:s1sar="http://www.esa.int/safe/sentinel-1.0/sentinel-1/sar" xmlns:gmi="http://sdi.eurac.edu/metadata/iso19139-2/schema/gmi" xmlns:s1sarl1="http://www.esa.int/safe/sentinel-1.0/sentinel-1/sar/level-1" xmlns:gco="http://www.isotc211.org/2005/gco" xmlns:gml="http://www.opengis.net/gml" xmlns:s1sarl2="http://www.esa.int/safe/sentinel-1.0/sentinel-1/sar/level-2" xmlns:gx="http://www.google.com/kml/ext/2.2" gco:isoType="gmd:MD_Metadata" xsi:schemaLocation="http://sdi.eurac.edu/metadata/iso19139-2/schema/gmi http://sdi.eurac.edu/metadata/iso19139-2/schema/gmi/gmi.xsd">
<gmd:identificationInfo>
<gmd:MD_DataIdentification>
<gmd:citation>
<gmd:CI_Citation>
<gmd:title xsi:type="gmd:PT_FreeText_PropertyType">
<gco:CharacterString>TITLE_1</gco:CharacterString>
</gmd:title>
<gmd:alternateTitle>
<gco:CharacterString>TITLE_2</gco:CharacterString>
</gmd:alternateTitle>
</gmd:CI_Citation>
</gmd:citation>
</gmd:MD_DataIdentification>
</gmd:identificationInfo>
</gmi:MI_Metadata>

以下是我正在使用的 XSL 文件:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<mdb:MD_Metadata xmlns:mri="http://standards.iso.org/iso/19115/-3/mri/1.0"
xmlns:mrl="http://standards.iso.org/iso/19115/-3/mrl/2.0"
xmlns:mas="http://standards.iso.org/iso/19115/-3/mas/1.0"
xmlns:mrs="http://standards.iso.org/iso/19115/-3/mrs/1.0"
xmlns:mda="http://standards.iso.org/iso/19115/-3/mda/1.0"
xmlns:mrd="http://standards.iso.org/iso/19115/-3/mrd/1.0"
xmlns:mdt="http://standards.iso.org/iso/19115/-3/mdt/2.0"
xmlns:mco="http://standards.iso.org/iso/19115/-3/mco/1.0"
xmlns:mex="http://standards.iso.org/iso/19115/-3/mex/1.0"
xmlns:msr="http://standards.iso.org/iso/19115/-3/msr/2.0"
xmlns:mds="http://standards.iso.org/iso/19115/-3/mds/2.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:gfc="http://standards.iso.org/iso/19110/gfc/1.1"
xmlns:mmi="http://standards.iso.org/iso/19115/-3/mmi/1.0"
xmlns:srv="http://standards.iso.org/iso/19115/-3/srv/2.1"
xmlns:lan="http://standards.iso.org/iso/19115/-3/lan/1.0"
xmlns:mac="http://standards.iso.org/iso/19115/-3/mac/2.0"
xmlns:gcx="http://standards.iso.org/iso/19115/-3/gcx/1.0"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:mrc="http://standards.iso.org/iso/19115/-3/mrc/2.0"
xmlns:gex="http://standards.iso.org/iso/19115/-3/gex/1.0"
xmlns:gml="http://www.opengis.net/gml/3.2"
xmlns:mdb="http://standards.iso.org/iso/19115/-3/mdb/2.0"
xmlns:cit="http://standards.iso.org/iso/19115/-3/cit/2.0"
xmlns:cat="http://standards.iso.org/iso/19115/-3/cat/1.0"
xmlns:mcc="http://standards.iso.org/iso/19115/-3/mcc/1.0"
xmlns:mdq="http://standards.iso.org/iso/19157/-2/mdq/1.0"
xmlns:mpc="http://standards.iso.org/iso/19115/-3/mpc/1.0"
xmlns:gmd="http://www.isotc211.org/2005/gmd"
xmlns:gco="http://standards.iso.org/iso/19115/-3/gco/1.0"
xmlns:gco="http://www.isotc211.org/2005/gco"
>
<mdb:identificationInfo>
<mri:MD_DataIdentification>
<mri:citation>
<cit:CI_Citation>
<cit:title>
<gco:CharacterString>
<xsl:value-of select="//gmd:identificationInfo/gmd:MD_DataIdentification/gmd:citation/gmd:CI_Citation/gmd:title/gco:CharacterString"/>
</gco:CharacterString>
</cit:title>
<cit:alternateTitle>
<gco:CharacterString>
<xsl:value-of select="//gmd:identificationInfo/gmd:MD_DataIdentification/gmd:citation/gmd:CI_Citation/gmd:alternatetitle/gco:CharacterString"/>
</gco:CharacterString>
</cit:alternateTitle>
</cit:CI_Citation>
</mri:citation>
</mri:MD_DataIdentification>
</mdb:identificationInfo>
</mdb:MD_Metadata>
</xsl:template>
</xsl:stylesheet>

它定义了两个命名空间。

所需的输出应该是:
<?xml version="1.0"?>
<mdb:MD_Metadata xmlns:mri="http://standards.iso.org/iso/19115/-3/mri/1.0"
xmlns:mrl="http://standards.iso.org/iso/19115/-3/mrl/2.0"
xmlns:mas="http://standards.iso.org/iso/19115/-3/mas/1.0"
xmlns:mrs="http://standards.iso.org/iso/19115/-3/mrs/1.0"
xmlns:mda="http://standards.iso.org/iso/19115/-3/mda/1.0"
xmlns:mrd="http://standards.iso.org/iso/19115/-3/mrd/1.0"
xmlns:mdt="http://standards.iso.org/iso/19115/-3/mdt/2.0"
xmlns:mco="http://standards.iso.org/iso/19115/-3/mco/1.0"
xmlns:mex="http://standards.iso.org/iso/19115/-3/mex/1.0"
xmlns:msr="http://standards.iso.org/iso/19115/-3/msr/2.0"
xmlns:mds="http://standards.iso.org/iso/19115/-3/mds/2.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:gfc="http://standards.iso.org/iso/19110/gfc/1.1"
xmlns:mmi="http://standards.iso.org/iso/19115/-3/mmi/1.0"
xmlns:srv="http://standards.iso.org/iso/19115/-3/srv/2.1"
xmlns:lan="http://standards.iso.org/iso/19115/-3/lan/1.0"
xmlns:mac="http://standards.iso.org/iso/19115/-3/mac/2.0"
xmlns:gcx="http://standards.iso.org/iso/19115/-3/gcx/1.0"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:mrc="http://standards.iso.org/iso/19115/-3/mrc/2.0"
xmlns:gex="http://standards.iso.org/iso/19115/-3/gex/1.0"
xmlns:gml="http://www.opengis.net/gml/3.2"
xmlns:mdb="http://standards.iso.org/iso/19115/-3/mdb/2.0"
xmlns:cit="http://standards.iso.org/iso/19115/-3/cit/2.0"
xmlns:cat="http://standards.iso.org/iso/19115/-3/cat/1.0"
xmlns:mcc="http://standards.iso.org/iso/19115/-3/mcc/1.0"
xmlns:mdq="http://standards.iso.org/iso/19157/-2/mdq/1.0"
xmlns:mpc="http://standards.iso.org/iso/19115/-3/mpc/1.0"
xmlns:gmd="http://www.isotc211.org/2005/gmd"
xmlns:gco="http://standards.iso.org/iso/19115/-3/gco/1.0">
<mdb:identificationInfo>
<mri:MD_DataIdentification>
<mri:citation>
<cit:CI_Citation>
<cit:title>
<gco:CharacterString>TITLE_1</gco:CharacterString>
</cit:title>
<cit:alternateTitle>
<gco:CharacterString>TITLE_2</gco:CharacterString>
</cit:alternateTitle>
</cit:CI_Citation>
</mri:citation>
</mri:MD_DataIdentification>
</mdb:identificationInfo>
</mdb:MD_Metadata>



有没有办法解决这个冲突并同时使用它们?或者你有什么其他建议?

最佳答案

您可以为“旧”命名空间使用另一个前缀。考虑以下示例:

XML

<gco:input xmlns:gco="http://www.isotc211.org/2005/gco">123</gco:input>

XSLT 1.0
<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:old="http://www.isotc211.org/2005/gco"
xmlns:gco="http://standards.iso.org/iso/19115/-3/gco/1.0"
exclude-result-prefixes="old">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>

<xsl:template match="/">
<gco:output>
<xsl:value-of select="old:input"/>
</gco:output>
</xsl:template>

</xsl:stylesheet>

结果
<?xml version="1.0" encoding="UTF-8"?>
<gco:output xmlns:gco="http://standards.iso.org/iso/19115/-3/gco/1.0">123</gco:output>

关于xml - 如何修复 : Attribute xmlns:gco redefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56357011/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com