Oracle8i Application Developer's Guide - XML Release 3 (8.1.7) Part Number A86030-01 |
|
Personalizing Data Display With XML: Portal-to-Go , 14 of 16
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.
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:
apply-templates
to process the contents of that element.
value-of
and for-each
, manipulate the content of matching elements.
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:
Table 7-2 Using Unique Transformers to Transform the Adapter's Simple Result XML
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>&</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. |
|