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. Some transform metadata into HTML pages for display. Others are used by the metadata model geoprocessing tools to perform portions of the importing, exporting, and upgrading metadata processes, or can be used to perform well-known metadata tasks. They can be found in the <ArcGIS Install Location>\Metadata\Stylesheets folder.
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.
- create an HTML page to display information about an ArcGIS item as part of a Web site. Use the ArcGIS.xsl stylesheet used to display metadata in ArcGIS or write your own.
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. These are the only functions that can be used with this tool and in the ArcGIS metadata editor.
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 Microsoft-specific functions 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 ESRI 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 ESRI XSLT function namespace. If the ESRI 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.
- 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.
- strtolower()—Changes the input text string to use only lowercase letters.
- striphtml()—If an XML element contains escaped HTML, this function will return the text it contains with all HTML markup removed. Refer to the ESRIISO2.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 file provided with ArcGIS for an example.
-
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 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 metadata—the information displayed in the FGDC metadata section in the Description tab. The FGDC elements will be ordered correctly in the output XML file.
The exported file can be published to a metadata catalog that requires information to be provided in the FGDC CSDGM metadata XML format. 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 metadata.
-
Metadata that is published to an external Website in HTML format will be indexed by Internet search engines such as Google if the Web site 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 |
An W3C-compliant XSLT 1.0 stylesheet file that defines the transformation that will be performed. | 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 merge upgraded FGDC with existing.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 Web site.
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", "#")