[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: inline xslt and stylesheets

Subject: Re: inline xslt and stylesheets
From: "Rich Stadnik" <stadnik@xxxxxxxx>
Date: Fri, 22 Nov 2002 13:44:18 -0500
inline xslt
Re: Inline style sheets:

I find the following approach works quite well for inline styles. There are
assuredly others that are equally effective.

For the overall application, I generally define a stylesheet that contains
assorted SIZES (widths and heights), COLORS (both absolute values and
functional definitions), and fonts. This stylesheet is then INCLUDEd into
all others which comprise the application.

For example, my sheet Z_STYLE will have assorted variables such as:

For sizes:
<xsl:variable name="SZ_THUMB_WIDTH"><xsl:value-of
select="60"/></xsl:variable>
<xsl:variable name="SZ_THUMB_HEIGHT"><xsl:value-of
select="80"/></xsl:variable>

For colors as absolute RGB values:
<xsl:variable name="CVAL_WHITE"><xsl:value-of
select="'#FFFFFF'"/></xsl:variable>
<xsl:variable name="CVAL_BLACK"><xsl:value-of
select="'#000000'"/></xsl:variable>
<xsl:variable name="CVAL_DKGRAY"><xsl:value-of
select="'#999999'"/></xsl:variable>
<xsl:variable name="CVAL_RED"><xsl:value-of select="'RED'"/></xsl:variable>

Colors are then defined by their usage:
<xsl:variable name="CVAL_BODYTEXT"><xsl:value-of
select="$CVAL_BLACK"/></xsl:variable>
<xsl:variable name="CVAL_BODYERR"><xsl:value-of
select="$CVAL_RED"/></xsl:variable>
<xsl:variable name="CVAL_LABELERR"><xsl:value-of
select="$CVAL_RED"/></xsl:variable>
<xsl:variable name="CVAL_LABELOK"><xsl:value-of
select="$CVAL_DKGRAY"/></xsl:variable>

Fonts are defined as follows:
<xsl:variable name="FONT_MED_NORM"><xsl:value-of select="'FONT: 9pt Arial,
Helvetica; FONT-WEIGHT: normal;'"/></xsl:variable>
<xsl:variable name="FONT_MED_BOLD"><xsl:value-of select="'FONT: 9pt Arial,
Helvetica; FONT-WEIGHT: bold;'"/></xsl:variable>

A variable is then created for each style:
<xsl:variable name="STY_TEXT_NORMAL">
    <xsl:value-of select="concat( '.TEXT_NORMAL {',
         'TEXT-DECORATION:',           'none',             ';',
         'COLOR:',                     $CVAL_BODYTEXT,     ';',
         $FONT_MED_NORM,               '}')"/></xsl:variable>

<xsl:variable name="STY_TEXT_BOLD">
    <xsl:value-of select="concat( '.TEXT_BOLD {',
         'TEXT-DECORATION:',           'none',             ';',
         'COLOR:',                     $CVAL_BODYTEXT,     ';',
         $FONT_MED_BOLD,               '}')"/></xsl:variable>

<xsl:variable name="STY_TEXT_STATUS_OK">
    <xsl:value-of select="concat( '.TEXT_STATUS_OK {',
         'TEXT-DECORATION:',           'none',             ';',
         'COLOR:',                     $CVAL_GREEN,        ';',
         $FONT_SM_NORM,                '}')"/></xsl:variable>

<xsl:variable name="STY_TEXT_STATUS_BO">
    <xsl:value-of select="concat( '.TEXT_STATUS_BO {',
         'TEXT-DECORATION:',           'none',             ';',
         'COLOR:',                     $CVAL_RED,          ';',
         $FONT_SM_NORM,                '}')"/></xsl:variable>


And (for convenience sake), a single variable is created for the whole
string:

<xsl:variable name="ESC_NL">&#x0d;&#x0a;</xsl:variable>
<xsl:variable name="STYLE_DEFS">
    <xsl:value-of select="concat($STY_TEXT_NORMAL,$ESC_NL)"/>
    <xsl:value-of select="concat($STY_TEXT_BOLD,$ESC_NL)"/>
    <xsl:value-of select="concat($STY_TEXT_STATUS_OK,$ESC_NL)"/>
    <xsl:value-of select="concat($STY_TEXT_STATUS_BO,$ESC_NL)"/>
    </xsl:variable>


Now, it's ready to be used in the rest of the application. For this I have a
template as part of a COMMON template stylesheet that all other application
specific templates CALL:

<xsl:template name="generate-panelhead">
         <xsl:param name="paneltitle"/>
    <HEAD>
         <TITLE>
              <xsl:value-of select="concat( 'My Site -- ', $paneltitle )" />
              </TITLE>
         <STYLE>
              <xsl:value-of select="$STYLE_DEFS"/>
              </STYLE>
         <SCRIPT>
              <xsl:attribute name="language">JavaScript</xsl:attribute>
              <xsl:attribute name="src"><xsl:value-of select="concat(
$PATH_JS, 'common.js'   )"/></xsl:attribute>
              </SCRIPT>
         </HEAD>
    </xsl:template>


And then to generate a particular cell, I might do the following:

    <TR>
         <TD valign="middle" align="left" width="100%"
height="{$SZ_HEADLINE_HEIGHT}" BGCOLOR="{$CVAL_HEADLINEBK}">
              <FONT class="BODY_HEADER">
    some text goes here
                   </FONT>
    <FONT>
         <xsl:attribute name="class">
              <xsl:choose>
                   <xsl:when test="????your test here???">
                        <xsl:value-of select="'LABEL_ERR'"/></xsl:when>
                   <xsl:otherwise>
                        <xsl:value-of
select="'LABEL_NORM'"/></xsl:otherwise>
                   </xsl:choose>
              </xsl:attribute>
         this will set style (and color) if this particular field is in
error
         </FONT>

              </TD>
         </TR>

Cheers.

Rich Stadnik
stadnik@xxxxxxxx



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.