Step 2: Create an XSL Style Sheet.

Page Index

Introduction

Create an XSL Style Sheet ("cat.xsl") with a set of rules to format the xml document.

<!- -The stylesheet is an XML document so the document begins with an xml declaration. - ->
<?xml version="1.0" encoding="UTF-8"?>

<!- - defines the start of the style sheet - ->
   <xsl:stylesheet version="1.0"     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"     xmlns:xs="http://www.w3.org/2001/XMLSchema">

<!- -defines the start of a template. The match="/" attribute matches the template to the root (/) of the XML source document. - ->
       <xsl:template match="/">
       <html>
       <head>
       <title>Biao Min Stylesheets</title>
       <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
       </head>
         <body>

<!- -allows you to loop through each selected element - ->
           <xsl:for-each select="lexicon">
             <xsl:for-each select="forms">
                <p>
                  <xsl:for-each select="form">
                    <xsl:for-each select="linguisticform">
                      <xsl:for-each select="unanalyzedform">
                           <span style="font-weight:bold;color:red; ">

<!- -applies a template rule to the current element or to the current element's child nodes. - ->
                             <xsl:apply-templates/>
                           </span>
                           .........
                      </xsl:for-each>
                     </xsl:for-each>
                   </xsl:for-each>
                  <br/>
                  <br/>
             </xsl:for-each>
          </body>
         </html>
         </xsl:template>
      </xsl:stylesheet>

How It Works

XSL works by recursively applying the individual <xsl:template> tags in the stylesheet to your XML source document. In this case, we only have one explicitly specified <xsl:template> tag, which is applied to the root of the document.

Within a given template there are a number of tags that can be used to do programming operations such as looping (<xsl:for-each>), printing the value of a tag (<value-of>), or performing more complex operations on a set of nodes (<xsl:sort>).

In this case there is an 'implicit' <xsl:template> rule which is being used to copy the text of the <unanalyzedform> tags from the source document to the target document.

Click here to view XSL file

Go to Steps 3 and 4

Back to Step 1

User Contributed Notes
How to Use XSL - Step 2
+ Add a comment
  + View comments

Back to top Credits | Glossary | Help | Navigation | Site Map | Site Search