XSLT Transformation (Conversion)
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:
- _MPXML2.xsl
- merge imported metadata with existing.xslt
- merge upgraded FGDC with existing.xslt
- prep metadata for export.xslt
- remove empty elements.xslt
- remove FGDC required hints.xslt
- remove synchronized elements.xslt
- remove unique identifiers.xslt
- upgrade ESRI-ISO to ArcGIS94.xslt
You can create your own XSLT stylesheets to perform tasks using the provided stylesheets as examples. For example, you might write a stylesheet to:
- Update addresses or phone numbers. Create a model that runs this process then uses the Metadata Importer tool to save the updated metadata to the original ArcGIS item.
- Remove information that you do not want publicly available before exporting or publishing the metadata. Create a model that runs this process before running the Export Metadata or Metadata Publisher tools.
- Export information to an HTML file so you can incorporate this information into a website. Create a script that runs this process periodically.
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
-
The output file produced by an XSLT stylesheet may be formatted as XML, HTML, or text, for example. The default output file name that will be provided by this tool will have a .xml file extension. If the XSLT stylesheet you are using does not produce an XML file you should provide a file name with a more appropriate file extension.
This tool can't process an ArcGIS item's metadata or a stand-alone metadata XML file using the XSL stylesheets provided with ArcGIS Desktop 9.3.1 and earlier versions because they don't use XSLT 1.0 technology. They use an older technology that is not supported by the .NET 3.5 Framework. These XSL stylesheets also can't be used with the ArcGIS metadata editor.
-
The XSLT Parameter can be used to pass a string or an XML file name to an XSLT stylesheet which can then use it to modify an item's metadata. For example, an XSLT stylesheet could take a phone number passed in as a string and update all phone numbers in the metadata. If an XML file is passed in with this parameter, an XSLT stylesheet can merge the information it contains with the source metadata.
Refer to the add unique identifier.xslt file provided with ArcGIS for an example of how to pass in a value and merge upgraded FGDC with existing.xslt for an example of merging information in a separate XML file with an ArcGIS item's metadata.
If you want to create a custom XSLT stylesheet to display or export metadata or XML files in ArcGIS, refer to the Microsoft documentation for the .NET 3.5 Framework for a complete list of the XSLT and XPath elements, functions and syntax that it supports. In addition to some standard XSLT functions, some .NET-specific functions are also available.
If you want to use your custom stylesheet both inside and outside ArcGIS you will have the best chance of success if you limit yourself to using XSLT 1.0 and XPath 1.0 elements, functions, and syntax. Non-Microsoft applications are unlikely to support any .NET-specific XSLT and XPath functions.
XSLT stylesheets that are exclusively used with this geoprocessing tool and the ArcGIS metadata editor can use some custom XSLT functions provided with ArcGIS to improve metadata handling and display. To use these functions the XSLT stylesheet must reference the URI of the ArcGIS XSLT function namespace http://www.esri.com/metadata/. For example, <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:esri="http://www.esri.com/metadata/">.
The ArcGIS XSLT functions must be prefaced by the prefix assigned to the ArcGIS XSLT function namespace. If the ArcGIS XSLT function namespace is assigned the prefix esri, as in the above example, the GuidGen() function would be used like this: <xsl:value-of select="esri:GuidGen()" />.
- GuidGen()—Returns a new globally unique identifier (GUID) value that does not include braces ({ and }). For example, a GUID can be included in the metadata to uniquely identify the metadata document or the resource it describes. Refer to the add unique identifier.xslt file provided with ArcGIS for an example.
- decodenodeset()—If an XML element contains escaped XHTML or XML, this function will return a node set that can be used in combination with the msxsl:node-set function to process the individual elements that were previously escaped. Refer to the ESRIISO2.xslt and ItemDescription.xslt files provided with ArcGIS for examples. For example, an item's spatial reference properties are automatically stored in an item's metadata as escaped XML data. The abstract and use limitations content that can be marked up in the metadata editor in preparation for publication to ArcGIS Online is stored as escaped XHTML.
- splitcoords()—Takes a comma-separated pair of x,y coordinates and converts them to a space-separated list. Refer to the upgrade ESRI-ISO to ArcGIS94.xslt file provided with ArcGIS for an example.
- strtoupper()—Changes the input text string to use only capital letters. Refer to the add unique identifier.xslt file provided with ArcGIS for an example.
- striphtml()—If an XML element contains escaped XHTML or XML, this function will return the text it contains with all the markup removed. That is, anything between two less than (<) or greater than (>) characters will be assumed to be markup and will be removed. Refer to the ESRIISO2.xslt, ItemDescription.xslt, and prep metadata for export.xslt files provided with ArcGIS as examples. For example, when preparing to export the contents of the abstract and use limitations elements to a standard metadata format, any XHTML markup that exists will be removed from the metadata content.
- strtolower()—Changes the input text string to use only lowercase letters. Refer to the auxCountries.xslt, auxLanguages.xslt, and auxUCUM.xslt files provided with ArcGIS for examples.
-
The Source Metadata parameter has a complex data type. If you use this tool in a model, create a variable for the Source Metadata parameter in ModelBuilder by right-clicking the tool and choosing Make Variable > From Parameter > Source Metadata.
-
If an ArcGIS item has metadata that was created in ArcGIS Desktop 9.3.1 or earlier using the FGDC metadata editor or in the current version of ArcGIS for Desktop using the FGDC metadata editor add-in and the item's metadata has been upgraded to ArcGIS metadata, the ArcGIS metadata will continue to include the original FGDC metadata XML elements. The metadata will also include other ArcGIS metadata elements.
You can export the original FGDC metadata elements using this tool with the _MPXML2.xsl file provided with ArcGIS. In the example above, this file would only export the item's original FGDC-format metadata content—the information displayed under the FGDC Metadata (read-only) heading in the Description tab. The FGDC elements will be ordered correctly in the output XML file.
The exported file can be validated with the FGDC XML Schema or DTD, or the USGS metadata utility known as mp. The USGS MP Metadata Translator performs this operation internally before processing the item's FGDc-format metadata content.
-
Metadata that is published to an external website in HTML format will be indexed by Internet search engines such as Google if the website exposes its content correctly.
Syntax
Parameter | Explanation | Data 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
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", "#")