Editing metadata for many ArcGIS items
Once metadata has been created, inevitably, some of the information it contains will change in time. If the information is specific to one ArcGIS item, you can edit its metadata to change the information. However, if the information that changed is included in the metadata for many ArcGIS items, the process of manually editing metadata for all affected items is very tedious.
The best approach for handling this situation is to create an XSLT stylesheet that can perform the edits for you. Use a model that edits the metadata with the XSLT Transformation tool, then imports the edited information back into the ArcGIS item using the Metadata Importer tool as illustrated below.
Creating an XSLT stylesheet to update metadata
There are many resources available on the Internet that can help you learn how to create XSLT stylesheets. However, the examples below will help you get started. They illustrate how to change an organization's contact information.
Suppose the original metadata included a metadata contact as shown below, where
- The individual name is Reception
- The organization name is ESRI Learning Center
- The street address is 380 New York St.
- The city is Redlands
- The state is California, CA
- The ZIP Code is 92373
- The country is the United States of America, US
- The e-mail address is info@esri.com
- The phone number is 909-793-2853
- The fax number is 909-793-4801
- The role specified for this contact is publisher, 010
An excerpt of a metadata XML document where the an organization's contact information must be updated.
<?xml version="1.0" encoding="UTF-8"?> <metadata> <mdContact> <rpIndName>Reception</rpIndName> <rpOrgName>Esri Learning Center</rpOrgName> <rpCntInfo> <cntAddress> <delPoint>380 New York St.</delPoint> <city>Redlands</city> <adminArea>CA</adminArea> <postCode>92373</postCode> <country>US</country> <eMailAdd>info@esri.com</eMailAdd> </cntAddress> <cntPhone> <voiceNum>909-793-2853</voiceNum> <faxNum>909-793-4801</faxNum> </cntPhone> </rpCntInfo> <role> <RoleCd value="010"/> </role> </mdContact> ... </metadata>
Some of this contact information must be edited as follows:
- Remove the individual name from the contact information.
- Change the ZIP Code to 92373-8100.
- Change the e-mail address to LearnGIS@esri.com.
- Change the phone number to 888-377-4575 x.1-3204.
- Add the location of a Web page where you can find information on the Internet, http://www.esri.com/training.
- Add information about when you can contact the organization, 8:00am to 5:00pm Pacific Time.
The rest of the contact information will stay the same.
The following XSLT stylesheet will perform these edits. The individual name metadata element will be removed. The entire address, with all its individual metadata elements, is updated at once. The phone number is updated separately from the rest of the phone information. To add the Web page and hours of availability, all other existing contact information must be copied so it isn't lost before the new information is added.
An XSLT stylesheet that edits contact information for one organization and copies all other metadata content.
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="2.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" /> <!-- process the metadata using the templates below --> <xsl:template match="/"> <xsl:apply-templates select="node() | @*" /> </xsl:template> <!-- copy all metadata conent --> <xsl:template match="node() | @*" priority="0"> <xsl:copy> <xsl:apply-templates select="node() | @*" /> </xsl:copy> </xsl:template> <!-- all metadata XSLT stylesheets used to update metadata should be identical to this example up to this point --> <!-- add the templates you'll use to update the metadata below --> <!-- remove the individual name from the contact information for the organization name Esri Learning Center --> <xsl:template match="rpIndName[../rpOrgName = 'Esri Learning Center']" priority="1" > </xsl:template> <!-- edit the address for any contact with the organization name Esri Learning Center --> <xsl:variable name="newAddress" > <cntAddress> <delPoint>380 New York St.</delPoint> <city>Redlands</city> <adminArea>CA</adminArea> <postCode>92373-8100</postCode> <country>US</country> <eMailAdd>LearnGIS@esri.com</eMailAdd> </cntAddress> </xsl:variable> <xsl:template match="cntAddress[../../rpOrgName = 'Esri Learning Center']" priority="1" > <xsl:copy-of select="$newAddress" /> </xsl:template> <!-- edit all contacts with the organization name Esri Learning Center to have a new phone number --> <xsl:variable name="newPhone">888-377-4575 x.1-3204</xsl:variable> <xsl:template match="voiceNum[../../../rpOrgName = 'Esri Learning Center']" priority="1" > <voiceNum><xsl:value-of select="$newPhone" /></voiceNum> </xsl:template> <!-- add hours of availability for the organization name Esri Learning Center --> <xsl:template match="rpCntInfo[../rpOrgName = 'Esri Learning Center']" priority="1" > <xsl:copy> <xsl:apply-templates select="node() | @*" /> <cntOnlineRes> <linkage>http://www.esri.com/training</linkage> </cntOnlineRes> <cntHours>8:00am to 5:00pm Pacific Time</cntHours> </xsl:copy> </xsl:template> </xsl:stylesheet>
When this XSLT is used to edit the example metadata shown above using the XSLT Transformation tool, the output XML file below will be created as output. Use the Metadata Importer tool to save these changes with the original ArcGIS item.
An excerpt of the updated metadata produced by the above XSLT stylesheet.
<?xml version="1.0" encoding="UTF-8"?> <metadata> <mdContact> <rpOrgName>Esri Learning Center</rpOrgName> <rpCntInfo> <cntAddress> <delPoint>380 New York St.</delPoint> <city>Redlands</city> <adminArea>CA</adminArea> <postCode>92373-8100</postCode> <country>US</country> <eMailAdd>LearnGIS@esri.com</eMailAdd> </cntAddress> <cntPhone> <voiceNum>888-377-4575 x.1-3204</voiceNum> <faxNum>909-793-4801</faxNum> </cntPhone> <cntOnlineRes> <linkage>http://www.esri.com/training</linkage> </cntOnlineRes> <cntHours>8:00am to 5:00pm Pacific Time</cntHours> </rpCntInfo> <role> <RoleCd value="010"/> </role> </mdContact> ... </metadata>
Several XSLT stylesheets are provided with ArcGIS Desktop to support the metadata geoprocessing models in the Conversion toolbox, in the <ArcGIS Desktop Install Location>\Metadata\Stylesheets\gpTools folder. Use these as examples.
When creating your own stylesheets, it helps to understand the XML format you're working with. An XML DTD describing the ArcGIS metadata XML format is provided in the <ArcGIS Desktop Install Location>\Metadata\Translator\Rules folder.