How to Make an XSL

From Earth Science Information Partners (ESIP)

< Interoperability of Air Quality Data Systems

How to Make an XSL

Introduction

Extensible Stylesheet Language (XSL) is a stylesheet language used for xml documents. An XSL Transformations (XSLT) is used to transform one xml document into a different desired xml. For example, pulling data from specified tags in a WCS or WMS document and putting them in the desired tags of an output ISO document. This process is fairly simple and can be used for many different applications. The following description will show how to create an XSL and use it to create multiple different ISO 19115 documents from many different original OGC Web Coverage Service (WCS) and OGC Web Map Service (WMS) xml documents. You will need a different XSLs for each desired input output resultant combination, but once the original xsl is made, it can easily be modified to accept a different input xml while outputting the same xml format.


STEP 1

Create a Mapping between your Input and Output Document.

The first step to creating an xsl is to create is to create a simple mapping between your input document and your desired output document. This is done to simplify the process later and to verify that there are enough elements to be correctly pulled to make the effort of creating and xsl worthwhile. If the output document contains only one or two of the elements from the input document then an xsl may not be of any use. On the other hand, if the output document contains multiple elements from the input then an xsl may be of help in creating the documents your desire. If you need to pull elements from several xml documents, there are two different techniques including simply combining the multiple xmls into one xml, secondly you can design your xsl to pull from multiple documents but this can be challenging when trying to create an automated process. We created a mapping of OGC WCS to ISO 19115 that included what elements could be pulled, what elements would be hand filled in and what elements could be standard for all ISO 19115 metadata we want to create. The mapping can be found at http://spreadsheets.google.com/ccc?key=pG0cD35SB_A8VMbcoUGpkUg&hl=en. Once you have a mapping, it will be very easy to see the abilities of your xsl.


STEP 2

Create the Output Document

The next step to creating an xsl is to create the output or desired xml document. In this case our desired output is an ISO 19115 document with at least partially filled with elements from the WCS and WMS documents. This can be achieved several different ways including using a service found on the web to create the document, manually creating it, or using an already created document similar to the desired output and modifying it to fit your needs. We started in two different ways: First we created an ISO 19115 document using the INSPIRE Metadata Editor (http://www.inspire-geoportal.eu/inspireEditor.htm) to manually create an ISO 19115 metadata record in xml. Secondly: We used an ISO 19115 xml document already filled in and verified to be correct, changed the elements to suit our specific datasets and services, and then verified out ISO 19115 document to be correct. This is the process that we used to create the document used in the creation of the XSL. The ISO 19115 document that we started with to create the xsl is found at: http://capita.wustl.edu/DataspaceMetadata_ISO/DataFed.AIRNOW_WCS.xml. Once the output document has been created, verified, and has been decided to be the final or at least starting point for the output document, you are ready to create an xsl.


STEP 3

Creating the XSL

Creating an XSL is an easy process that begins with modifying your output document created in the last step by saving it as .xsl instead of .xml. This will keep your original output document unchanged and there for reference when needed. The next step is to add the following lines to the beginning and end of the output document:

Add the following lines to the beginning:

 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output method="xml"/>
 <xsl:template match="/">

Add the following lines to the end:

 </xsl:template>
 </xsl:stylesheet>

If the document that you are pulling from contains namespaces, then you need to add them to lines added in the previous step in the beginning of the document as follows:


EXAMPLE: Original Document:

   <gmd:MD_Metadata xmlns:gco="http://www.isotc211.org/2005/gco" 
   xmlns:gmd="http://www.isotc211.org/2005/gmd" 
   xmlns:gml="http://www.opengis.net/gml" 
   xmlns:gts="http://www.isotc211.org/2005/gts" 
   xmlns:srv="http://www.isotc211.org/2005/srv" 
   xmlns:xlink="http://www.w3.org/1999/xlink" 
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 <gmd:fileIdentifier>
   <gco:CharacterString>http://capita.wustl.edu/DataspaceMetadata_ISO/metadata/DataFed.AIRNOW_WCS.xml</gco:CharacterString>
 </gmd:fileIdentifier>
 <gmd:language>
  .
  .
  .

This document contains many different namespaces including: xmlns:gco="http://www.isotc211.org/2005/gco" xmlns:gmd="http://www.isotc211.org/2005/gmd" xmlns:gml="http://www.opengis.net/gml" xmlns:gts="http://www.isotc211.org/2005/gts" xmlns:srv="http://www.isotc211.org/2005/srv" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

The beginning lines will then look like:

 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:gco="http://www.isotc211.org/2005/gco" xmlns:gmd="http://www.isotc211.org/2005/gmd" xmlns:gml="http://www.opengis.net/gml"         
 xmlns:gts="http://www.isotc211.org/2005/gts" xmlns:srv="http://www.isotc211.org/2005/srv" xmlns:xlink="http://www.w3.org/1999/xlink"  
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance”>
 <xsl:output method="xml"/>
 <xsl:template match="/">