xsl-list
[Top] [All Lists]

Re: [xsl] xsl:choose and xsl:when

2007-08-29 16:18:50
[somehow this didn't reach the list, retry. probably outdated now though..]

Hi Oryan,

see my comments,

Cheers,
Abel

oryann9 wrote:
<?xml version="1.0" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
<xsl:output method="html"/>
<xsl:template match="/">
     <HTML>
     <HEAD>
     <TITLE>My Phone Book</TITLE>
     </HEAD>
     <BODY BGCOLOR="BLACK">
          <xsl:apply-templates select="//LISTING" />

You probably want just LISTING here. You are selecting every possible
LISTING from the root through all the document when you use //LISTING.

     </BODY>
     </HTML>
</xsl:template>
<xsl:template match="LISTING">
     <FONT COLOR="WHITE"><xsl:value-of
select="LAST"/>,
          <xsl:value-of select="FIRST"/></FONT>
     <FONT COLOR="orange" SIZE="+2"><xsl:value-of
select="PHONE"/>
<xsl:choose>
      <xsl:when test="boolean(PHONE/@TYPE)">
           (<xsl:value-of select="PHONE/@TYPE" />)

No need for an xsl:choose. In almost all cases that I've seen on this
list, xsl:choose is over-used, because it feels so easy (or looks so
much like in the other programming languages). Instead, use:

<FONT COLOR="orange" SIZE="+2">
   <xsl:apply-templates select="PHONE" />

then, have twotemplate matches (one for empty or non-existing @TYPE, the
other for all other @TYPE):

<xsl:template match="PHONE[(_at_)TYPE='' | not(@TYPE)]" >
   <xsl:value-of select="."/> (HOME)
</

<xsl:template match="PHONE[(_at_)TYPE != '']">
   <xsl:value-of select="."/> (<xsl:value-of select="PHONE/@TYPE" />)
</


      </xsl:when>
       <xsl:when test="(PHONE/@TYPE='')">
            (HOME)
      </xsl:when>
      <xsl:otherwise>
           (HOME)
      </xsl:otherwise>
</xsl:choose>
     </FONT>
</xsl:template>
</xsl:stylesheet>





--~------------------------------------------------------------------
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>