首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何修复:属性xmlns:gco重新定义

如何修复:属性xmlns:gco重新定义
EN

Stack Overflow用户
提问于 2019-05-29 09:13:03
回答 1查看 671关注 0票数 0

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

代码语言:javascript
复制
xmlns:gco="http://standards.iso.org/iso/19115/-3/gco/1.0"

旧元数据具有以下名称空间:

代码语言:javascript
复制
xmlns:gco="http://www.isotc211.org/2005/gco

如果将两者都放入XSLT的头中,则会得到error属性xmlns:gco重新定义。

我尝试删除其中一个,但XSLT无法提取正确的值,因此得到了空字符串:

代码语言:javascript
复制
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输入文件的一部分。

代码语言:javascript
复制
<?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文件:

代码语言:javascript
复制
<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>

它定义了两个名称空间。

预期的产出应是:

代码语言:javascript
复制
<?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>

是否有办法解决这一冲突并同时利用这两种冲突?或者你还有什么其他建议吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-05-29 09:32:36

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

XML

代码语言:javascript
复制
<gco:input xmlns:gco="http://www.isotc211.org/2005/gco">123</gco:input>

XSLT1.0

代码语言:javascript
复制
<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>

结果

代码语言:javascript
复制
<?xml version="1.0" encoding="UTF-8"?>
<gco:output xmlns:gco="http://standards.iso.org/iso/19115/-3/gco/1.0">123</gco:output>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56357011

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档