Oracle8i Application Developer's Guide - XML
Release 3 (8.1.7)

Part Number A86030-01

Library

Solution Area

Contents

Index

Go to previous page Go to beginning of chapter Go to next page

Personalizing Data Display With XML: Portal-to-Go , 14 of 16


Portal-to-Go: XSL Stylesheet Transformers

XSL stylesheets are XML documents that specify the processing rules for other XML documents. An XSL stylesheet, like a Java Transformer, is specific to a particular DTD, and should handle all elements declared in that DTD. When it finds an element in a source document, it follows the rules defined for the element to format its content.

Portal-to-Go XSL Stylesheet Transformer Example 1: Converting Simple Result Documents to Plain Text

This XSL Transformer example is included in the Portal-to-Go initial repository and is the XSL version of the Java Transformer shown above. It converts Simple Result documents to plain text.

<xsl:stylesheet xmlns:xsl="http://www.w3.org/XSL/Transform/1.0">
   <xsl:template match="/">
      <xsl:apply-templates></xsl:apply-templates>
   </xsl:template>
      <xsl:template match="SimpleTextItem | SimpleFormItem | SimpleMenuItem">
      <xsl:text>
      </xsl:text>
      <xsl:value-of select="."></xsl:value-of>
   </xsl:template>
   <xsl:template match="SimpleRow">
      <xsl:text></xsl:text>
      <xsl:for-each select="./SimpleCol">
         <xsl:text></xsl:text>
         <xsl:value-of select="."></xsl:value-of>
      </xsl:for-each>
   </xsl:template>
</xsl:stylesheet>

In this example. the XSL stylesheet performs the following tasks:

  1. Selects a Simple Result element using pattern-matching semantics. The element "/", for example, matches the document's root element.

  2. Uses apply-templates to process the contents of that element.

  3. Descends the source element tree, selecting and processing each sub-element. Character instructions, such as value-of and for-each, manipulate the content of matching elements.

    • The value-of element extracts the actual content of the element.

    • The for-each element applies iterative processing.

Each Markup Language Requires a Unique Transformer

Each unique markup language requires a unique Transformer. The Stock Data example assumes that the PDA and cell phone use different markup languages (Tiny HTML and WML), so we need two Transformers. Once they're built, though, these Transformers can process content from any Adapter that generates Simple Result XML.

Table 7-2 lists the Adapter's SimpleResult XML code and the markup language generated by two transformers:

Portal-To-Go Stylesheet Transformer Example 2: Customizing a WML1.1 Transformer Stylesheet

WML Browsing on Phone.com Browsers

When using the Phone.com browser the navigation model requires you to select the [Link] option before proceeding. You can customize the stylesheet to change this behavior. For example, you can add the following to the WML1.1 Transformer stylesheet:

| The SimpleForm Mapping 
+--> 
<xsl:template match="SimpleForm"> 
<p> 
 <xsl:variable name="theTarget"> 
 <xsl:value-of select="@target"/> 
 <xsl:for-each select="SimpleFormItem | SimpleFormSelect"> 
 <xsl:text>&#38;</xsl:text> 
 <xsl:value-of select="@name"/> 
 <xsl:text>=$(</xsl:text> 
 <xsl:value-of select="@name"/> 
 <xsl:text>)</xsl:text> 
</xsl:for-each> 
</xsl:variable> 
<xsl:apply-templates/> 

<!-- Ensure [Link] is selected --> 
<select> 
<option> 
<onevent type="onpick"> 
<go href="{$theTarget}"/> 
</onevent> 
<xsl:choose> 
<xsl:when test="boolean(@submit)"> 
<xsl:value-of select="@submit"/> 
</xsl:when> 
<xsl:otherwise>Submit</xsl:otherwise> 
</xsl:choose> 
</option> 
</select> 
</p> 

<!-- Ensure [Link] is selected ends --> 
<!-- 
<a href="{$theTarget}"> 
  <xsl:choose> 
    <xsl:when test="boolean(@submit)"> 
    <xsl:value-of select="@submit"/> 
    </xsl:when> 
  <xsl:otherwise>Submit</xsl:otherwise> 
  </xsl:choose> 
</a> 
<br/> 
</p> 
--> 
</xsl:template>

Go to previous page Go to beginning of chapter Go to next page
Oracle
Copyright © 1996-2000, Oracle Corporation.

All Rights Reserved.

Library

Solution Area

Contents

Index