Subject: RE: Style Sheet Guidelines
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Fri, 31 Dec 2004 12:01:04 -0000
|
I don't see why you consider xsl:attribute to be "more formal" or "stricter"
than an attribute in a literal result element. Being more long-winded
doesn't make it more formal; and just because an attribute value template is
more concise, that doesn't make it a "shorthand".
Go for readability.
In Saxon 8.x, the two forms generate identical run-time code.
Michael Kay
http://www.saxonica.com/
> -----Original Message-----
> From: Chris_Graham@xxxxxxxxxxx [mailto:Chris_Graham@xxxxxxxxxxx]
> Sent: 31 December 2004 00:52
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: Style Sheet Guidelines
>
> Hi All,
>
> We have an issue of style guidelines to address when writing
> XSL files.
>
> Basically, it revolves around readability and performance.
>
> We have the choice between the more formal form:
>
> <!-- Format given value as a Product/Policy Type (HOM/MOT/CTP/CTQ) -->
> <xsl:template name="productOptions">
> <xsl:param name="name"/>
> <select>
> <xsl:attribute name="name"><xsl:value-of
> select="$name"/></xsl:attribute>
> <option value=''></option>
> <option value='MOT'>Motor</option>
> <option value='HOM'>Home</option>
> <option value='CTP'>CTP</option>
> </select>
> </xsl:template>
>
> And a shorthand form:
>
> <!-- Format given value as a Product/Policy Type (HOM/MOT/CTP/CTQ) -->
> <xsl:template name="productOptions">
> <xsl:param name="name"/>
> <select name="{$name}">
> <option value=''></option>
> <option value='MOT'>Motor</option>
> <option value='HOM'>Home</option>
> <option value='CTP'>CTP</option>
> </select>
> </xsl:template>
>
> The difference is in the formal declaration of the attribute
> 'name' of the
>
> 'select' element.
>
> The first way is the the stricter, the second is easier to
> understand and
> work with.
>
> When we are working with templates, we call it the same way:
>
> <xsl:call-template name="productOptions">
> <xsl:with-param name="name">Product01</xsl:with-param>
> </xsl:call-template>
>
> It outputs the same results.
>
> Whilst these differences are relatively minor, in this
> example, they do
> become more profound when applied to every instance where
> they should be.
>
> Consider this shorthand example:
>
> <FONT size="5">
> Good morning!<br/>
> </FONT>
>
> This is easier to read, as it is standard HTML.
>
> Compare it now to the formal example:
>
> <FONT>
> <xsl:attribute name="size">5</xsl:attribute>
> Good morning!<br/>
> </FONT>
>
> The output is identical:
>
> <FONT size="5">
> Good morning!<br>
> </FONT>
>
> and
>
> <FONT size="5">
> Good morning!<br>
> </FONT>
>
>
> The only difference between the formal and the shorthand is that the
> shorthand form shows up as a problem in the annotation
> portion of each
> page (the right hand column where you will see a small red
> square). It
> does not effect the SAX parsing of the file, WSAD just issues
> some problem
>
> warnings. (You can always open the file in a text editor
> inside WSAD and
> you will not see these conditions).
>
> The version that uses the <xsl:attribute> form takes about
> 10-15% longer
> to run, which is as expected (as it has extra parsing to do [and uses
> slightly more memory as well]).
>
> I prefer the shorthand form as it is easier to read and consumes less
> resources at runtime.
>
> I would appreciate some input from others more knowledable
> than myself in
> what works best for them (and why).
>
> -Chris
>
>
>
> **************************************************************
> *********************
> This email contains information confidential to AAMI Limited.
> If you are not the intended recipient, you must not disclose
> or use the information in it. If you have received this email
> in error, please notify us immediately by return email, and
> delete this email and any attached documents.
> AAMI Limited is not responsible for any changes made to a
> document other than those made by AAMI Limited or for the
> effect of the changes on the document meaning.
> **************************************************************
> *********************
|