我正在使用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>
是否有解决此冲突并同时使用两者的方法?或者您还有其他建议吗?
答案 0 :(得分:1)
您可以为“旧”名称空间使用另一个前缀。考虑以下示例:
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>