Oracle8i Application Developer's Guide - XML Release 3 (8.1.7) Part Number A86030-01 |
Library | Service | Contents | Index

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:

- Tiny HTML for the PDA, which can format and display both quotes and headlines

- WML for the cell phone, which can only display quotes.

  ##### Table 7-2 Using Unique Transformers to Transform the Adapter's Simple Result XML

  Adapter's Simple Result XML | Unique Transformers
  --- | ---
  <SimpleResult> <SimpleText title="Quote"> <SimpleTextItem name="Ticker"> ORCL </SimpleTextItem> <SimpleTextItem name="Price"> 90 3/8 </SimpleTextItem> </SimpleText> <SimpleText title="Headlines"> <SimpleTextItem name = "Headline1"> * Oracle surges. </SimpleTextItem> <SimpleTextItem name = "Headline2"> * NASDAQ closes higher. </SimpleTextItem> <SimpleTextItem name = "Headline3"> * US stocks bolt ahead. </SimpleTextItem> </SimpleText> </SimpleResult> | Tiny HTML for PDA <html> <p>Quote</p> <p>Ticker: ORCL</p> <p>Price: 90 3/8</p> <p>Headlines:</p> <p>* Oracle surges.</p> <p>* NASDAQ closes higher.</p> <p>* US stocks bolt ahead.</p> </html> WML for Cell Phone <?xml version "1.0"?> <!DOCTYPE WML PUBLIC "-//WAPFORUM/DTD WML 1.0//EN" "http://www.wapforum.org.DTD.wml.xml"> <WML> <CARD NAME="QUOTE_CARD" TITLE="Quote Card"> ORCL 90 3/8 </CARD> </WML>

### 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>

| Copyright © 1996-2000, Oracle Corporation. All Rights Reserved. |
Library | Service | Contents | Index