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

Re: global language parameter

Subject: Re: global language parameter
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Tue, 16 Feb 2010 12:40:09 -0500
Re:  global language parameter
Dear Charles,

In addition to everything you've done, I would suggest you now consider refactoring this logic into a dedicated mode.

That is, instead of

At 04:02 AM 2/15/2010, you wrote:
<xsl:template name="add-style">
<xsl:attribute name="style">
<!--what is the margin component-->
<xsl:choose>
<xsl:when test="@rend='indent'">
<xsl:text>text-indent:12mm; margin-top: 0;margin-bottom: 0; </xsl:text>
<xsl:text>line-height:9mm;</xsl:text>
</xsl:when>
<xsl:when test="@rend='plain'">
<xsl:text>text-indent:0;margin-left:0; margin-top:0;</xsl:text>
<xsl:text>margin-bottom: 0; line-height:9mm;</xsl:text>
</xsl:when>
<xsl:when test="@rend='blockquote'">
<xsl:text>text-indent:0;margin-left:12mm; margin-top:1em;</xsl:text>
<xsl:text>margin-bottom: 1em; margin-right: 2em;</xsl:text>
<xsl:text>line-height:9mm;</xsl:text>
</xsl:when>

... etc ... you have


<xsl:template match="*[@rend='indent']" mode="add-style">
  <xsl:text>text-indent:12mm; margin-top: 0;margin-bottom: 0; </xsl:text>
  <xsl:text>line-height:9mm;</xsl:text>
</xsl:template>

<xsl:template match="*[@rend='plain']" mode="add-style">
  <xsl:text>text-indent:0;margin-left:0; margin-top:0;</xsl:text>
  <xsl:text>margin-bottom: 0; line-height:9mm;</xsl:text>
</xsl:template>

<xsl:template match="*[@rend='blockquote']" mode="add-style">
  <xsl:text>text-indent:0;margin-left:12mm; margin-top:1em;</xsl:text>
  <xsl:text>margin-bottom: 1em; margin-right: 2em;</xsl:text>
  <xsl:text>line-height:9mm;</xsl:text>
</xsl:template>

Then it's simply a matter of having

<xsl:attribute name="style">
  <xsl:apply-templates select="." mode="add-style"/>
</xsl:attribute>

I would argue this is a bit cleaner and more extensible, in addition (perhaps) to performing better, than a long choose/when/otherwise.

You can go further with this also. For example, a dedicated mode could add the font styling based on language, too, using the lang() function to discriminate matches. And you can distinguish easily between properties added only to block elements (margins and such) vs properties added to both blocks and inlines.

Finally, you might consider abstracting the regularities between the styles -- in this case, probably into named templates, which are good when boilerplate is really boilerplate.

Cheers,
Wendell



======================================================================
Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
----------------------------------------------------------------------
  Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================

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.