XSLT Transformation (Conversion)

License Level:BasicStandardAdvanced

Summary

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.

XSLT stylesheets can be used to perform a variety of modifications to ArcGIS metadata or an XML file. Several XSLT stylesheets are provided with ArcGIS for Desktop. They can be found in the <ArcGIS Installation Location>\Metadata\Stylesheets folder. These stylesheets are described in the tables below.

The following stylesheets produce the HTML documents that are used to display information about an item in the Description tab. They extract content from an item's metadata and add HTML formatting instructions to it. These stylesheets import many XSLT templates from other files in the ArcGIS_Imports folder; the imported templates perform most of the work. If you are interested in creating custom stylesheets for display, you can learn more about these stylesheets by reading the documentation provided with the ArcGIS Metadata Toolkit.

ArcGIS.xsl

Displays an item's complete metadata content. It is referenced by all metadata styles except the default Item Description style.

ArcGIS_ItemDescription.xsl

Displays only a concise description of the item. It is referenced by the default Item Description metadata style.

The following stylesheets, provided in the <ArcGIS Installation Location>\Metadata\Stylesheets\gpTools folder, take an item's metadata, process it, then save the resulting XML document to a new XML file. The goal of this operation might be to filter an item's metadata before using it outside of ArcGIS. Or, the goal might be to alter the item's metadata; in this case, the resulting XML file can be saved back to the original item as its metadata using the Metadata Importer tool. A model or script can be created that first runs this tool with a stylesheet to update the metadata content, then immediately saves the changes back to the item. The following stylesheets are provided with ArcGIS for Desktop to perform some well-defined metadata tasks.

add unique identifier.xslt

Adds or changes the unique identifier stored in the item's metadata. The identifier modified by this stylesheet is stored in the Esri PublishedDocID metadata element and is used to identify the document in a metadata catalog such as an ArcIMS Metadata Service or a Geoportal.

exact copy of.xslt

Creates an exact copy of the item's metadata as an XML file. For example, you might use this stylesheet to save a copy of a geodatabase item's metadata to a local file so it can be examined.

generate metadata template.xslt

Copies ArcGIS metadata content to a new XML file that can be imported to other items as a metadata template. Synchronized metadata content is excluded from the template and any empty elements are removed.

remove empty elements.xslt

Removes empty XML elements. After other stylesheets have been used to remove unwanted metadata content, empty XML elements may remain. Empty XML elements can cause problems if you later try to validate an item's metadata. For example, if an element is optional but empty, you will often receive an error message because the element has no value, whereas the metadata would be valid if the empty element was removed.

remove entries from FGDC lineage.xslt

Removes process steps added to the FGDC-format lineage by ArcGIS Desktop 9.3.1. Process steps were added to the FGDC-format lineage when metadata was imported to an item and when the item was copied to a new location. This information is not added to an item's lineage using the current version of ArcGIS, and is not upgraded to the ArcGIS metadata format along with the rest of the item's lineage.

remove FGDC required hints.xslt

Removes any FGDC-format metadata elements that contain the text REQUIRED. These text strings were added by ArcGIS Desktop 9.3.1 when FGDC-format metadata was created to indicate which metadata elements are required to create valid FGDC CSDGM metadata. However, these strings can cause problems if you later try to validate an item's metadata. When the default text is present, the element will be considered valid because it contains text, even though the text doesn't provide any information about the item. Default text strings are not added by the current version of ArcGIS, and these strings are not upgraded to the ArcGIS metadata format along with the rest of an item's metadata content.

remove geoprocessing history.xslt

Removes an item's geoprocessing history. While all of the metadata geoprocessing tools are designed to preserve an item's geoprocessing history, over time, that history can grow so large that the item's metadata becomes difficult to handle as an XML document. In these circumstances it may be necessary to remove an item's geoprocessing history.

remove local storage info.xslt

Removes any machine names that may exist in the item's metadata. Depending on where the machine name was found, the metadata element containing the information may be removed, or the machine name may be removed from a UNC path, or the element's value may be updated to identify the location as being withheld.

remove pre94 metadata elements.xslt

Removes any ESRI-ISO format XML elements and any FGDC CSDGM-format XML elements from an item's metadata that are not included in the ArcGIS metadata format.

remove synchronized elements.xslt

Removes any information that was added to an item's metadata by the ArcGIS metadata synchronization process.

remove thumbnail.xslt

Removes an item's thumbnail. While all of the metadata geoprocessing tools are designed to preserve an item's thumbnail, in some circumstances you might want to remove the item's thumbnail. You can remove one item's thumbnail when you edit its metadata in the Description tab. With this script you could run a batch process to remove thumbnails from many items.

remove unique identifiers.xslt

Removes all unique identifiers from an item's metadata, including all identifiers that may have been added by ArcGIS and any identifiers provided using a metadata editor. Identifiers should never be copied to another item.

_MPXML2.xsl

Extracts FGDC CSDGM format XML elements from the item's metadata, if they exist, and orders them correctly. The information extracted by this stylesheet is the content that appears under the FGDC Metadata (read-only) heading in the Description tab.

Some of the stylesheets provided with ArcGIS for Desktop are used by the metadata geoprocessing tools to perform portions of the importing, exporting, and upgrading processes:

You can create your own XSLT stylesheets to perform tasks using the provided stylesheets as examples. For example, you might write a stylesheet to:

XSLT stylesheets that modify ArcGIS metadata should not remove information in the Esri and Binary metadata elements except if the output XML will be used outside of ArcGIS.

Usage

Syntax

XSLTransform_conversion (source, xslt, output, {xsltparam})
ParameterExplanationData Type
source

The item whose metadata will be converted or a stand-alone XML file that will be converted.

Data Element; Layer
xslt

A W3C-compliant XSLT 1.0 stylesheet file that defines the transformation that will be performed.

Several stylesheets are provided with ArcGIS and are available in the <ArcGIS Installation Location>\Metadata\Stylesheets folder.

File
output

A file that will be created containing the converted metadata.

The type of file created depends on the output method specified in the XSLT stylesheet.

File
xsltparam
(Optional)

An XML file or string that will be passed to the XSLT stylesheet.

To capture this parameter in the XSLT stylesheet, add <xsl:param name="gpparam" /> to the top of the XSLT stylesheet after the xsl:output element and before the first xsl:template element. See add unique identifier.xslt for an example.

File; String

Code Sample

Export metadata to an HTML file

Uses the ArcGIS.xsl XSLT stylesheet provided with ArcGIS to export metadata to an HTML file for use in a website.

import arcpy
from arcpy import env
env.workspace = "C:/data"
#set local variables
dir = arcpy.GetInstallInfo("desktop")["InstallDir"]
xslt = dir + "Metadata/Stylesheets/ArcGIS.xsl"
arcpy.XSLTransform_conversion("vegetation", xslt, "vegetation.html", "#")

Environments

Related Topics

Licensing Information

ArcGIS for Desktop Basic: Yes
ArcGIS for Desktop Standard: Yes
ArcGIS for Desktop Advanced: Yes
10/24/2012