xsl-list
[Top] [All Lists]

Re: [xsl] Onion-skin overriding stylesheet

2011-09-07 04:49:26
Taken to the extreme, you should also avoid xsl:value-of in favour of
apply-templates with a text() matching template.

Could you elaborate on the following with perhaps an example case.


Instead of:

<xsl:template match="title">
  (do some stuff)
  <xsl:value-of select="."/>
</xsl:template>

do:

<xsl:template match="title">
  (do some stuff)
  <xsl:apply-templates/>
</xsl:template>

as then if the requirement comes in to wrap the title in a <span
class="foo"> for some customer, you can just add the follwing template
in a new entry point stylesheet:

<xsl:template match="title/text()">
  <span class="foo">
    <xsl:value-of select="."/>
  </span>
</xsl:template>

(when you know title only contains a string)

If the template used value-of instead of the apply-templates then you
would need to override the whole <title> matching template:

<xsl:template match="title">
  (do some stuff)
  <span class="foo">
    <xsl:value-of select="."/>
  </span>
</xsl:template>

...and duplicate the (do some stuff) code.   That then means for any
change to the code thats been duplicated you have to make the change
in 2 places - both the hassle of making the same change twice, and
remembering to do it in the first place.

Alterntively you could just edit the existing code, maybe pass in a
param and use a choose/when... that is a short road to a world of pain
when the inevitable requests come in for more changes or more
customers come along.

cheers
andrew






-- 
Andrew Welch
http://andrewjwelch.com

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>