Siebel Portal Framework Guide > Delivering Content to External Web Applications > Manipulating Siebel XML with XSL Stylesheets and XSLT >
Sample XSL Stylesheet
The following XSL style sheet code sample is used to transform the WML-based Siebel Wireless application into HTML through the XML Web Interface. This code shows how a list view in the Wireless application is converted to HTML.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html" media-type="text/html"/>
<!-- This style sheet process the XML output for both the Splash screens and standard views-->
<!-- ====================== Root Document Processing ========================-->
<!-- Document Root-->
<xsl:template match="/">
<xsl:apply-templates select="//APPLICATION/SCREEN/VIEW/APPLET"></xsl:apply-templates>
</xsl:template>
<!-- ============================ View Processing ===========================-->
<!-- List Base mode Template-->
<xsl:template match="APPLET">
<HTML>
<BODY>
<b>
<!-- Applet Title Label-->
<xsl:value-of select="CONTROL[@ID='1']"/>
<!-- for calendar title -->
<xsl:value-of select="CALENDAR/@TITLE"/>
</b>
<br></br>
<!-- XML No Record found and other alerts -->
<xsl:if test="string-length(ALERT)>0 and @CLASS='CSSFrameCalRerouteBase'">
<xsl:value-of select="ALERT"/>
<br></br>
</xsl:if>
<!-- Search and Title with data or other links -->
<xsl:apply-templates select="CONTROL[@ID=2 or @ID=3 or @ID=4 or @ID=5 or @ID=6 or @ID=7 or @ID=8 or @ID=9]"/>
<!-- Separator line -->
<xsl:apply-templates select="CONTROL[@ID=1000]"/>
<!-- Display fields for list of records here-->
<xsl:apply-templates select="LIST"></xsl:apply-templates>
<xsl:if test="string-length(@ROW_COUNTER)>0">
<xsl:value-of select="@ROW_COUNTER"></xsl:value-of>
<br></br>
</xsl:if>
<!-- control link for New, Main Menu, etc.. -->
<xsl:apply-templates select="CONTROL[@ID>=40 and @HTML_TYPE='Link']"/>
</BODY>
</HTML>
</xsl:template>
<!-- ================= Control and Link Processing ===================-->
<xsl:template match="CONTROL">
<xsl:choose>
<xsl:when test="@HTML_TYPE='Link'">
<xsl:call-template name="build_simple_link"></xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="."></xsl:value-of><br></br>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="build_simple_link">
<xsl:variable name="link">
<xsl:apply-templates select="ANCHOR"></xsl:apply-templates>
</xsl:variable>
<xsl:element name="A">
<xsl:attribute name="HREF"><xsl:value-of select="$link"/></xsl:attribute>
<xsl:value-of select="@CAPTION"/>
</xsl:element>
<br/>
</xsl:template>
<!-- ============================ List processing ==========================-->
<!-- LIST Template builds a list of records -->
<xsl:template match="LIST">
<!-- first get the URL from the RS_HEADER element-->
<xsl:variable name="link">
<xsl:apply-templates select="RS_HEADER/METHOD[@NAME='Drilldown']"/>
</xsl:variable>
<!-- capture the URL before the SWERowId parameter-->
<xsl:variable name="link-prefix">
<xsl:value-of select="substring-before($link,'R=')"/>
</xsl:variable>
<!-- capture the URL after the SWERowId parameter-->
<xsl:variable name="link-suffix">
<xsl:value-of select="substring-after($link,'R=')"/>
</xsl:variable>
<!-- capture the field with the drilldown enabled - use later to build drilldown -->
<xsl:variable name="drilldowncontrol">
<xsl:value-of select="RS_HEADER/METHOD[@NAME='Drilldown']/@FIELD"></xsl:value-of>
</xsl:variable>
<!-- loop through the rows in the RS_DATA element -->
<xsl:for-each select="RS_DATA/ROW">
<!-- pickup the Row Id for the Row so we can rebuild the SWERowId URL parameter-->
<xsl:variable name="rowid">
<xsl:value-of select="@ROWID"/>
</xsl:variable>
<!-- loop through each field and control in the Row -->
<xsl:for-each select="FIELD|CONTROL">
<xsl:choose>
<!-- if the field is the drilldown field then create a link on the display data-->
<xsl:when test="@NAME = $drilldowncontrol">
<xsl:element name="A">
<xsl:attribute name="HREF">
<xsl:value-of select="concat(normalize-space($link-prefix),'R=',$rowid,$link-suffix)"/>&F=<xsl:value-of select="@VARIABLE"/>
</xsl:attribute>
<xsl:value-of select="."></xsl:value-of>
</xsl:element>
</xsl:when>
<!-- otherwise just display the data as is-->
<xsl:otherwise>
<xsl:value-of select="."></xsl:value-of>
</xsl:otherwise>
</xsl:choose>
<!-- need a break if field is not empty -->
<xsl:variable name="empty_field">
<xsl:value-of select="."/>
</xsl:variable>
<xsl:if test="string-length($empty_field)!=0"><br></br></xsl:if>
</xsl:for-each>
</xsl:for-each>
<!-- Show separator line only if has one or more record -->
<xsl:variable name="row_data">
<xsl:value-of select="normalize-space(RS_DATA/ROW)"/>
</xsl:variable>
<xsl:if test="string-length($row_data)>0">
<xsl:text>- - - -</xsl:text><br></br>
</xsl:if>
<!-- show More link only if there is next record set -->
<xsl:variable name="more_link">
<xsl:value-of select="normalize-space(RS_HEADER/METHOD[@NAME='GotoNextSet']/@CAPTION)"/>
</xsl:variable>
<xsl:if test="string-length($more_link)>0">
<xsl:element name="A">
<xsl:attribute name="HREF">
<xsl:apply-templates select="RS_HEADER/METHOD[@NAME='GotoNextSet']"/>
</xsl:attribute>
<xsl:value-of select="$more_link"></xsl:value-of>
</xsl:element>
<br></br>
</xsl:if>
</xsl:template>
<!-- =================== Anchor URL Processing =======================-->
<!-- ANCHOR Template builds the URL for drilldowns and links -->
<xsl:template match="ANCHOR">
<xsl:text>start.swe?</xsl:text>
<xsl:apply-templates select="CMD|INFO"/>
</xsl:template>
<xsl:template match="CMD">
<xsl:value-of select="@NAME"/>=<xsl:value-of select="@VALUE"/>
<xsl:apply-templates select="ARG"/>
</xsl:template>
<xsl:template match="ARG">
<xsl:variable name="arg">
<xsl:if test="string-length(normalize-space(.)) >0">
<xsl:variable name="argstring">
<xsl:choose>
<xsl:when test="@NAME='Pu' or @NE='R' or @NAME='Rs'">
<xsl:value-of select="translate(normalize-space(),'%2B','+')'"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="normalize-space()"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:value-of select="$argstring"/>
</xsl:if>
</xsl:variable>
<xsl:text>&</xsl:text>
<xsl:value-of select="@NAME"></xsl:value-of>=<xsl:value-of select="$arg"></xsl:value-of>
<!--<xsl:text>&</xsl:text>-->
<!--<xsl:value-of select="@NAME"/>=<xsl:value-of select="translate($arg,'%2B','+')'"/>-->
</xsl:template>
<xsl:template match="INFO">
<xsl:variable name="info">
<xsl:if test="string-length(normalize-space(.)) >0">
<!--<xsl:value-of select="."/>-->
<xsl:value-of select="normalize-space(.)"/>
</xsl:if>
</xsl:variable>
<xsl:text>&</xsl:text>
<xsl:value-of select="@NAME"/>=<xsl:value-of select="$info"/>
</xsl:template>
</xsl:stylesheet>
|