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 Desktop. They can be used to save a copy of an item's metadata to an XML file, save a copy of the metadata display to an HTML file, and change an item's metadata content. These XSLT stylesheets can be found in the <ArcGIS Installation Location>\Metadata\Stylesheets folder.
Learn more about the XSLT stylesheets provided with ArcGIS Desktop
You can create your own XSLT stylesheets to perform tasks using the provided stylesheets as examples. For example, you might write a stylesheet to do the following:
- Update addresses or phone numbers. Create a model that runs this process and 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 XML or HTML file that can be incorporated 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 when 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 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 uppercase 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, pointing to Make Variable, pointing to From Parameter, and then clicking Source Metadata.
If an ArcGIS item has metadata that was created in ArcGIS Desktop 9.3.1 or earlier using the FGDC metadata editor 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 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
arcpy.conversion.XSLTransform(source, xslt, output, {xsltparam})
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 the add unique identifier.xslt file 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
Licensing information
- Basic: Yes
- Standard: Yes
- Advanced: Yes