|
|
The IMesh Toolkit
[ Work In Hand > Components >
OAI Normalization tools]
Using XSLT Stylesheet 1: a step-by-step guide
This page guides you through the process of downloading and using XSLT
Stylesheet 1 to make tranformations on OAI records.
- Obtain an XSLT processor.
These are 3 examples of processors that are freely available.
Follow the instructions provided with the tools for installing and using them.
- The Saxon
XSLT processor by Michael Kay - a java application.
- Xalan
from the Apache XML project.
- Microsoft's
MSXML 4.0 includes an XSLT processor.
A list of XSLT software is available at dmoz.org
- Download the Stylesheet
Download
(If the browser does not prompt you to download the file, and displays the file instead, right-click and use Save-as).
- Prepare your input files
The input files need to conform to the OAI-defined schema for encoding
DC in XML.
You can consult the
official version of the schema, or take a look at
a schematic view of a record that conforms
to the schema. If you are making your records available in an OAI repository,
you should already support a version of your records in the required schema,
as this is a mandatory requirement for repositories.
The input file may consist of one or more records within the same file.
You must then add a root <Records> element to the document.
For example, if your list of records is a result of an OAI ListRecords request,
change the
<ListRecords> opening and closing tags to a <Records> tag (and delet
e and delete any enclosing elements so that Record becomes the root element).
Sample file with one record
Sample file containing multiple records
- Edit the Stylesheet
You can edit the stylesheet using any normal text editor of your choice
e.g. Notepad on Windows.
This is the portion of the stylesheet that you need to look for:
<xsl:template match="dc:type">
<xsl:choose>
<xsl:when test="contains(.,'Tutorials')">
<xsl:copy>
<xsl:text>LearningMaterialCourseware</xsl:text>
</xsl:copy>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="current()"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
The above portion causes only one change in the record. If dc:type
elements are present in the input documents, the text
"LearningMaterialCourseware" will appear in the output
record replacing the text "Tutorials" if it appeared as the content
of the dc:type element.
You can change any of the dc elements that will be affected, and
for each element, you can carry out different text replacements.
To change the element affected, change dc:type to the name of
the element that you want to transform, in the match
attribute of the template.
E.g. in the following line change "dc:type" to "dc:subject".
<xsl:template match="dc:type">
to
<xsl:template match="dc:subject">
To change the substituted text, change
the test condition so that it contains the text that you would like
substituted.
Change "Tutorials" to the phrase that you want to replace:
<xsl:when test="contains(.,'Tutorials')">
Then put the new text that you would like to
insert instead of "LearningMaterialCourseware" in this line:
<xsl:text>LearningMaterialCourseware</xsl:text>
To carry out more than one substitution in the same run,
for the same element type, repeat the test condition,
i.e. repeat this whole portion, adding one for each substitution:
<xsl:when test="contains(.,'Tutorials')">
<xsl:copy>
<xsl:text>LearningMaterialCourseware</xsl:text>
</xsl:copy>
</xsl:when>
To carry out substitutions in more than one element in the same run,
for each different element that you would like to change,
repeat the whole of the template element (editing the element name and text as
needed), and adding as many test conditions as you need:
<xsl:template match="dc:type">
<xsl:choose>
<xsl:when test="contains(.,'Tutorials')">
<xsl:copy>
<xsl:text>LearningMaterialCourseware</xsl:text>
</xsl:copy>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="current()"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
Note that in this version only the elements in the metadata portion will be affected.
The content of <type> tags within other sections
(e.g. children of the about element) will not be affected.
Finally, edit this line so that it contains only the elements which are not
being changed by the stylesheet, and remove the names the names of the
elements which have their own template:
<xsl:template match="header|about|dc:title|dc:creator|dc:subject|dc:description|dc:publisher|dc:contributor|dc:date|dc:format|dc:identifier|dc:source|dc:language|dc:relation|dc:coverage|dc:rights">
- Apply the stylsheet to your input file
This step depends on which processor you are using. Refer to the
documentation for the processor for details. Below is an example
using Xalan.
Example: if your records are in a file called myInputrecords.xml,
and you would like the output to be written to a file called
myChangedrecords.xml, using the stylesheet OAIstylesheet1.xsl
for Xalan use the command:
Xalan -o myChangedRecords.xml myInputFile.xml OAIstylesheet1.xsl
Note that there is no requirement for all the files to be in the same directory.
The following would work just as well:
Xalan -o OAI/newrecords/myChangedRecords.xml OAI/records/myInputFile.xml OAI/stylesheets/OAIstylesheet1.xsl
assuming those are the correct paths to all the files.
- Example of output
The result of applying the instructions in the sample configuration file
to the sample input file with multiple records will produce this output file.
|