Re: trouble creating a link (style suggestions)

Subject: Re: trouble creating a link (style suggestions)
From: Dan Morrison <dman@xxxxxxxx>
Date: Tue, 30 May 2000 15:18:11 +1200
Wayne Davis wrote:
> 
> Here's what works...(also posting the code I'm using to create a web based
> link, in the event that someone else finds it useful - _someone_ else out
> there must be as green as I am with this stuff <g>)

Good example, but (with your forgiveness) I can't resist 'tidying' it. 
I make some assumptions about EMAIL and WEB being exclusive, and the
only options (which may not be the case). The select="." may have
side-effects in other context.

<li>
<a>
  <font face="Arial" size="2" color="aqua">
    <xsl:attribute name="href">
      <xsl:if test="EMAIL[.!='']">
        mailto:<xsl:value-of select="EMAIL"/>
      </xsl:if>
      <xsl:if test="WEB[.!='']">
        <xsl:value-of select="WEB"/>
      </xsl:if>
    </xsl:attribute>
    <xsl:value-of select="."/>
  </font>
</a>
</li>


2 Points.
Your example, while good for an example and clarity, contains repetition
which can be avoided. Two identical 'font' definitions especially could
trip up later maintainence.

I think it's better html if the "a" is inside the "li". NS in particular
/may/ link strangely.

Also, while I've not tested it thoughoughly, I usually get away with
just test="EMAIL". I'm unsure of the legality of this tho'.

Apologies, as this is only personal, stylistic opinion. Sometimes I pay
so much attention to 'elegant' I forget about 'practical'. ( But my Perl
one-liners are fab  ;-) )

OTOH, you may want to move in the other direction and split it out into
separate <xsl:template match="EMAIL">... chunks. Much more versatile. 
This is actually how I do it in practice, as I have freetext content
which may include links at any position...


I'll get down off my high-horse now...



thud.


.dan.





Snippet from one of my template libraries...

<!--
################## Generic default template ####################
##                       'EMAIL'                              ##
##  Turns a 'EMAIL' into an 'mailto' tag.                     ##
-->
  <xsl:template match="EMAIL">
  <a><xsl:attribute name="href">mailto:<xsl:value-of select="."
/></xsl:attribute><xsl:value-of select="." /></a>
  </xsl:template>
<!--
##                                                            ##
################################################################
 -->


-- 
:=====================:====================:
: Dan Morrison        : The Web Limited    :
:  http://here.is/dan :  http://web.co.nz  :
:  dman@xxxxxxxx      :  danm@xxxxxxxxx    :
:  04 384 1472        :  04 495 8250       :
:  025 207 1140       :                    :
:.....................:....................:
: If ignorance is bliss, why aren't more people happy?
:.........................................:


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


Current Thread