Pergunta

There have been a lot of metadata changes in the latest versions of ArcGIS. I am specifically working with version 10.2 and am trying to update several python scripts that utilize multiple geoprocessing tools. These scripts used to be able to easily search the metadata for the geoprocessing history and output that information to a text log file.

There is a tool in ArcGIS that uses "the .NET 3.5 XML software to transform an ArcGIS item's metadata or any XML file using an XSLT 1.0 stylesheet and save the result to an XML file." The tool is called XSLT Transformation. Several transformations are provided by ESRI for use with this tool. One in particular does the exact opposite of what I would like to achieve: copy all metadata except the geoprocessing history. Below is the xslt file I am referring to.

<?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>

I have never worked with xslt files before, but I am quick to learn. If possible, I would like to create one that will copy only the geoprocessing history (lineage) but also create a valid xml file. I tried to play around with it a bit, but when I used my transformation, the result was an error that said something like "would result in an invalid XML document".

Any help would be appreciated.

Foi útil?

Solução

You should be able to use something like this:

<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>

or more simply (since you're not modifying anything in 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>

It's currently wrapping the output in results, but you can change that or remove it completely if there is only one lineage.

I'm also surprised that ESRI isn't using a namespace in this XML. If you have any problems, add a sample input and output as suggested by Lingamurthy CS.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top