Difference between revisions of "How to Make an XSL"

From Earth Science Information Partners (ESIP)
Line 151: Line 151:
  
 
GEOSS ISO19115 Metadata Editor
 
GEOSS ISO19115 Metadata Editor
http://128.252.167.10/web/guest/iso-metadata-editor
+
http://geoaip-aq.wustl.edu/web/guest/iso-metadata-editor
  
 
INSPIRE Metadata Editor
 
INSPIRE Metadata Editor
Line 165: Line 165:
 
Geoss Pilot2
 
Geoss Pilot2
 
https://sites.google.com/site/geosspilot2/Home
 
https://sites.google.com/site/geosspilot2/Home
 
 
 
  
 
=== Background: ===
 
=== Background: ===

Revision as of 08:30, September 3, 2009

< 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="/">

Example of an XSL:

   <xsl:stylesheet version="1.0"
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   xmlns:n="http://www.opengis.net/wcs" 
   xmlns:gml="http://www.opengis.net/gml" 
   xmlns:xlink="http://www.w3.org/1999/xlink"
   xmlns:srv="http://www.isotc211.org/2005/srv">
   <xsl:output method="xml"/>
   <xsl:template match="/">
   <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:xlink="http://www.w3.org/1999/xlink" 
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <gmd:fileIdentifier>
   .
   .
   .
  </gmd:statement>
  </gmd:LI_Lineage>
  </gmd:lineage>
  </gmd:DQ_DataQuality>
  </gmd:dataQualityInfo>
  </gmd:MD_Metadata> 
  </xsl:template>
  </xsl:stylesheet>

The next step in creating the xsl is to replace elements in the xsl that you want pull from the original document to the output document with the following line:

   <xsl:value-of select="WCS_Capabilities/Service/responsibleParty/contactInfo”/>

with the path correct to the element in the original document. This line will pull from the the original document whatever is between the tags:

   <WCS_Capabilities><Service><responsibleParty> <contactInfo> DATA TO BE PULLED </contactInfo></responsibleParty></Service></WCS_Capabilities>

There are several variations to this line that pulls from the original document to the output document including if the data is in the tag, if there is mutiple elements in the tag, and many other situations that will each take a unique solution that will be described later. For the first time replace one element with this line of code, and the correct path to ensure that it is working. There are several ways to transform your xml but the easiest is to add a line to the original document as follows:

Original Document:

   <?xml version="1.0" encoding="ISO-8859-1"?>
   <A>
   YOUR DATA
   <C>YOUR DATA</C> 
   .
   .
   .
   </A>

Original Document with XSL linked:

   <?xml version="1.0" encoding="ISO-8859-1"?>
   <?xml-stylesheet type="text/xsl" href="YOUR XSL.xsl"?>
   <A>
   YOUR DATA
   <C>YOUR DATA</C> 
   .
   .
   .
   </A>

Once this line has been added, whenever you open the original xml document in a web browser such as internet explorer, the document should appear as your XSL does with the information pulled through from the original document. Repeat this process, checking each time to make sure that it is working correctly, until all elements needed to be pulled are.



Resources:

Airnow WCS GetCapabilities ISO 19115 http://capita.wustl.edu/DataspaceMetadata_ISO/DataFed.AIRNOW_WCS.xml

Airnow WMS GetCapabilities ISO 19115 http://capita.wustl.edu/DataspaceMetadata_ISO/DataFed.AIRNOW_WMS.xml

WCS GetCapabilities to ISO 19115 XSL: http://capita.wustl.edu/xslt/XSL_WCS_GETCAP_TO_ISO.xsl

WMS GetCapabilities to ISO 19115 XSL: http://capita.wustl.edu/xslt/XSL_WMS_GETCAP_TO_ISO.xsl

GEOSS ISO19115 Metadata Editor http://geoaip-aq.wustl.edu/web/guest/iso-metadata-editor

INSPIRE Metadata Editor http://www.inspire-geoportal.eu/InspireEditor/

Mapping of WCS GetCapabilities to ISO 19115 http://spreadsheets.google.com/ccc?key=pG0cD35SB_A8VMbcoUGpkUg&hl=en

WC3 - XML Schema and XSLT Schema http://www.w3.org/TR/xmlschema11-1/ http://www.w3.org/Style/XSL/

Geoss Pilot2 https://sites.google.com/site/geosspilot2/Home

Background:

ISO 19115: A schema describing geographic information and services. TAG -

START TAG - <TAG> - Used to start an xml element.

END TAG - </TAG> - Used to end an xml element.

Example: “<TAG> This is sample text. </TAG>”

XML – Extensible Markup Language

XSL – Extensible Stylesheet Language - A stylesheet language used for xml document

XSLT – XSL Transformations - Used to transform one input xml document into a desired output xml document by pulling elements from the original into the output.

Example: pulling metadata elements from specified tags in a Web Coverage Service (WCS) document and putting them in the desired tags of a output document, specifically ISO 19115




This document is a work in process and more information will continue to be added. Please post comments or questions that you have about creating XSLs.