[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: inline xslt and stylesheets
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">
</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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|