[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

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


Subject: Re: [xsl] xsl:choose and xsl:when
From: David Carlisle <davidc@xxxxxxxxx>
Date: Wed, 29 Aug 2007 16:09:23 +0100

You have no container elements around your entries.
So the LISTING elements don't really appear to be any meaning,
(in what way is jane smith to be treated differently?)

In your code you have

<xsl:template match="LISTING">
     <FONT COLOR="WHITE"><xsl:value-of
select="LAST"/>,

select="LAST" selects _all_ the last name elements, and then value-of
(in XSLT 1) gives the string value of the first, discarding the rest, so
you just get Smith (from Derek Smith) in the first listing and Smith
(from Jane Smith) in the second.

similarly your test  test="PHONE/@TYPE" is testing if _any_ phone in
this listing has a type attribute.

I think you want to ignore the LISTING element and process the FIRST
elements (such positional grouping is much easier in XSLT2) 

(Not that XSLT cares, but you do know that <FONT has been deprecated in
HTML for years:-)


<?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="/PHONEBOOK/LISTING/FIRST" />
     </BODY>
     </HTML>
</xsl:template>

<xsl:template match="FIRST">
<xsl:text>&#10;</xsl:text>
<br/>
<xsl:value-of select="."/>
<xsl:apply-templates select="following-sibling::*[1][self::LAST|self::PHONE]"/>
</xsl:template>

<xsl:template match="LAST">
 <xsl:text> </xsl:text>
 <xsl:value-of select="."/>
  <xsl:apply-templates select="following-sibling::*[1][self::PHONE]"/>
</xsl:template>

<xsl:template match="PHONE">
 <xsl:text> </xsl:text>
 <xsl:value-of select="."/>
 <xsl:choose>
   <xsl:when test="@TYPE"> (<xsl:value-of select="@TYPE"/>) </xsl:when>
   <xsl:otherwise> (HOME) </xsl:otherwise>
 </xsl:choose>
  <xsl:apply-templates select="following-sibling::*[1][self::PHONE]"/>
</xsl:template>

</xsl:stylesheet>





$ saxon phone.xml phone.xsl 
<HTML>
   <HEAD>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
   
      <TITLE>My Phone Book</TITLE>
   </HEAD>
   <BODY BGCOLOR="BLACK">
      <br> Derek   Smith   614-757-2123  (CELL) 
      <br> Joseph   Chow   614-757-2323  (HOME) 
      <br> Corey   Pohl   614-806-1416  (HOME) 
      <br> Tiko   Lewis   614-232-3434  (CELL) 
      <br> Kurt   Smith   419-455-9090  (HOME) 
      <br>Jane Smith 1-800-234-5678 (HOME)  1-555-222-3333 (HOME) 
   </BODY>
</HTML>

________________________________________________________________________
The Numerical Algorithms Group Ltd is a company registered in England
and Wales with company number 1249803. The registered office is:
Wilkinson House, Jordan Hill Road, Oxford OX2 8DR, United Kingdom.

This e-mail has been scanned for all viruses by Star. The service is
powered by MessageLabs. 
________________________________________________________________________


Current Thread
Keywords