[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: David Carlisle <davidc@xxxxxxxxx>
Date: Wed, 29 Aug 2007 16:09:23 +0100
Re:  xsl:choose and xsl:when
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

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.