Page 178 - Building Digital Libraries
P. 178

Sharing Data—Harvesting, Linking, and Distribution



                   <xsl:template name=“print_animals”>
                   <xsl:param name=“name” />
                   <b>Animals:</b>
                   <xsl:value-of select=“$name” />
                   <br />
                   </xsl:template>
                   <xsl:template name=“print_people”>
                   <xsl:param name=“name” />
                   <b>People:</b>
                   <xsl:value-of select=“$name” />
                   <br />
                   </xsl:template>
                   </xsl:stylesheet>


                 In this XSLT sample document, we see the use of a number of common
                 XSLT processing elements. First, there is the use of the xsl:template ele-
                 ment. This creates a capsulized set of processing instructions that are reused
                 whenever a specific set of criteria is met. In this case, the template is run
                 when the root node is encountered. Looking at the document, one can get
                 a better idea how this is utilized, looking at the print_title, print_animal,
                 and print_people templates. Sorting is accomplished by utilizing the xsl:sort
                 command and identifying the sort element. In this case, the sort element
                 was the title attribute. Applying this XSLT to the source XML document
                 produces the following HTML output (see figure 7.3).
                     The display in figure 7.3 could be changed quickly by making minor
                 modifications to the XSLT document. For example, if one wanted to re-sort
                 by a different element, one would simply need to modify the xsl:sort tag
                 or add a conditional to print only the items that had elephants. And while
                 this is only a simple XSLT example, it demonstrates the primary purpose
                 for which it was developed—to transform XML structures into new and   FIGURE 7.3
                 useful documents.                                                     XSLT/XML Transform
                     So how does this relate to digital repositories and their metadata? Since   Output
                 most digital repositories utilize XML-based data structures, XSLT can
                 be used as a method for moving data into and out of different metadata
                 schemas or to create new displays. The earlier examples presented a very
                 simplistic view of XSLT—but how could this be used to translate metadata
                 from one format to another? The answer is that the translation gets more
                 complicated.




                   <?xml version=“1.0” encoding=“UTF-8”?>
                   <xsl:stylesheet version=“1.0” xmlns:dc=“http://purl.org/dc/elements/1.1/”  xmlns=“http://www.loc.
                   gov/MARC21/slim” xmlns:xsl=“http://www.w3.org/1999/XSL/Transform” exclude-result-prefixes=“dc”>
                   <xsl:output method=“xml” indent=“yes”/>
                   <xsl:template match=“/”>
                   <record xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance” xsi:schemaLocation=“http://www.loc.
                   gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd” >
                   <xsl:element name=“leader”>
                   <xsl:variable name=“type” select=“dc:type”/>
                   <xsl:variable name=“leader06”>

                                                                                                                    (Cont.)
                                                                                                                     163
   173   174   175   176   177   178   179   180   181   182   183