首页 文章

自定义xslt以仅从ArcGIS元数据输出地理处理历史记录

提问于
浏览
1

最新版本的ArcGIS中存在大量元数据更改 . 我特别使用10.2版本,并尝试更新多个使用多个地理处理工具的python脚本 . 这些脚本以前能够轻松搜索元数据以查找地理处理历史记录,并将该信息输出到文本日志文件 .

ArcGIS中有一个工具,它使用“.NET 3.5 XML软件使用XSLT 1.0样式表转换ArcGIS项目的元数据或任何XML文件,并将结果保存到XML文件中 . ”该工具称为XSLT Transformation . ESRI提供了几种转换功能,可用于此工具 . 其中一个与我想要实现的完全相反:复制除地理处理历史之外的所有元数据 . 下面是我指的xslt文件 .

<?xml version="1.0" encoding="UTF-8"?>
<!-- Processes ArcGIS metadata to remove empty XML elements to avoid exporting and validation errors. -->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
    <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" omit-xml-declaration="no" />

    <!-- start processing all nodes and attributes in the XML document -->
    <!-- any CDATA blocks in the original XML will be lost because they can't be handled by XSLT -->
    <xsl:template match="/">
        <xsl:apply-templates select="node() | @*" />
    </xsl:template>

    <!-- copy all nodes and attributes in the XML document -->
    <xsl:template match="node() | @*" priority="0">
        <xsl:copy>
            <xsl:apply-templates select="node() | @*" />
        </xsl:copy>
    </xsl:template>

    <!-- templates below override the default template above that copies all nodes and attributes -->

    <!-- exclude geoprocessing history -->
    <xsl:template match="/metadata/Esri/DataProperties/lineage" priority="1">
    </xsl:template>

</xsl:stylesheet>

我之前从未使用过xslt文件,但我很快就学会了 . 如果可能,我想创建一个只复制地理处理历史记录(沿袭)但也创建一个有效的xml文件 . 我尝试了一下它,但当我使用我的转换时,结果是一个错误,说“会导致无效的XML文档” .

任何帮助,将不胜感激 .

1 回答

  • 0

    你应该可以使用这样的东西:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
        <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" omit-xml-declaration="no" />
    
        <xsl:template match="@*|node()">
            <xsl:copy>
                <xsl:apply-templates select="@*|node()"/>
            </xsl:copy>
        </xsl:template>
    
        <xsl:template match="/*">
            <results>
                <xsl:apply-templates select="Esri/DataProperties/lineage"/>
            </results>
        </xsl:template>
    
    </xsl:stylesheet>
    

    或者更简单(因为你没有修改 lineage 中的任何内容):

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
        <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" omit-xml-declaration="no" />
    
        <xsl:template match="/*">
            <results>
                <xsl:copy-of select="Esri/DataProperties/lineage"/>
            </results>
        </xsl:template>
    
    </xsl:stylesheet>
    

    它当前正在将输出包装在 results 中,但如果只有一个 lineage ,则可以更改或完全删除它 .

    我也很惊讶ESRI没有在这个XML中使用命名空间 . 如果您有任何问题,请按照Lingamurthy CS的建议添加样本输入和输出 .

相关问题