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

Re: xsl:choose and xsl:when

Subject: Re: xsl:choose and xsl:when
From: Abel Braaksma <abel.online@xxxxxxxxx>
Date: Thu, 30 Aug 2007 01:16:54 +0200
Re:  xsl:choose and xsl:when
[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[@TYPE='' | not(@TYPE)]" >
   <xsl:value-of select="."/> (HOME)
</

<xsl:template match="PHONE[@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>

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.