Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 18th, 2007, 07:18 AM
Registered User
 
Join Date: Aug 2007
Location: , , .
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default XSL Issue

Hi,
I am having problems rendering my xml with xslt.
Only the top template displays.
Here is my xml and xslt. Your help would be greatly appreciated.

<?xml version="1.0" encoding="windows-1252"?>
<courses>
   <course num="1">
      <crs_no>49</crs_no>
      <crs_title>Computer Science</crs_title>
      <crs_type>UnderGrad</crs_type>
      <crs_letters>Computer Science</crs_letters>
      <crs_duration>4</crs_duration>
      <crs_acad_year>2008</crs_acad_year>
      <cao_code>TR001</cao_code>
      <cao_points_current>300</cao_points_current>
      <cao_points_last>400</cao_points_last>
      <faculty_code>F10</faculty_code>
      <crs_ft_pt>FT</crs_ft_pt>
      <crs_places>300</crs_places>
      <crs_url>http://www.cs.tcd.ie</crs_url>
      <crs_content>
        <h5>Overview</h5>
 <p>Computer science is the study of everything to do with computers, from the pioneering theoretical discoveries on logic and calculation in the nineteenth and twentieth centuries through to the development of very early computers in the middle of the last century right up to the present day, when computers have become both powerful and commonplace.</p>
<h5>Is this the right course for you? </h5>
<p>Computer Science at Trinity is a challenging and exciting course. You will graduate with a thorough grounding in computer science, and this will take considerable effort on your part. </p>
</crs_content>
</course>
</courses>
----------------------------------------------------------------------

<?xml version='1.0' encoding='utf-8' ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="courses/course">
<table width="10%" border="0">
  <tr>
    <td colspan="2"><h4><xsl:apply-templates select="crs_title"/></h4></td>
  </tr>
  <tr>
    <td><strong>Award</strong></td>
    <td><xsl:apply-templates select="crs_letters"/></td>
  </tr>
  <tr>
    <td width="15%"><strong>Course Code</strong></td>
    <td><xsl:apply-templates select="cao_code"/></td>
  </tr>
  <tr>
    <td width="15%"><strong>Duration</strong></td>
    <td><xsl:apply-templates select="crs_duration"/> Years
        <xsl:choose>
        <xsl:when test="crs_ft_pt='1'">Full Time</xsl:when>
        <xsl:otherwise>Part Time</xsl:otherwise>
        </xsl:choose>
    </td>
  </tr>
  <tr>
    <td width="15%"><strong>No. of places</strong></td>
    <td><xsl:apply-templates select="crs_places"/> Places</td>
  </tr>
  <tr>
    <td><strong>Min Entry Points <xsl:apply-templates select="crs_acad_year"/></strong></td>
    <td><xsl:apply-templates select="cao_points_current"/> Points</td>
  </tr>
  <tr>
    <td width="15%"><strong>Min Entry Points 2006</strong></td>
    <td><xsl:apply-templates select="cao_points_last"/> points</td>
  </tr>
  </table>
</xsl:template>

<xsl:template match="h5">
    <h5><xsl:apply-templates /></h5>
</xsl:template>

<xsl:template match="p">
  <p><xsl:apply-templates /></p>
</xsl:template>

<xsl:template match="link">
   <a href="{@url}"><xsl:value-of select="@name" /></a>
</xsl:template>

<xsl:template match="img">
   <img src="{@src}" alt="{@alt}" align="left" width="100" height="150" hspace="5"/>
</xsl:template>

<xsl:template match="ul">
   [list]
   <xsl:for-each select="li">
    <li><xsl:value-of select="text()"/></li>
   </xsl:for-each>
  </ul>
</xsl:template>

<xsl:template match="ol">
 <ol>
 <xsl:for-each select="li">
  <li><xsl:value-of select="text()"/></li>
 </xsl:for-each>
</ol>
</xsl:template>

<xsl:template match="*">
    <xsl:apply-templates/>
</xsl:template>


</xsl:stylesheet>

Reply With Quote
  #2 (permalink)  
Old October 18th, 2007, 07:35 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Can you clarify, you only have one course and you get one table? Templates that match img and ol have no elements to process, what exactly did you expect to see?

PS Okay I see what you mean, the p text is not displaying.
That's because you don't have anywhere that specifies to apply templates at the appropriate point. It's okay for the course element as that gets handled by the built-in templates and default processing.


--

Joe (Microsoft MVP - XML)
Reply With Quote
  #3 (permalink)  
Old October 18th, 2007, 07:46 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Depends where you want the text, you could add another row to the table:
Code:
<tr>
    <td width="15%"><strong>Content</strong></td>
    <td><xsl:apply-templates select="crs_content"/> points</td>
  </tr>
--

Joe (Microsoft MVP - XML)
Reply With Quote
  #4 (permalink)  
Old October 18th, 2007, 07:59 AM
mhkay's Avatar
Wrox Author
Points: 18,481, Level: 59
Points: 18,481, Level: 59 Points: 18,481, Level: 59 Points: 18,481, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,960
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Your <h5>, <p> etc element are part of crs_content but you never visit that part of the tree. I would expect the template for courses/course to contain an apply-templates select="crs_content" at the point where you want this material to be output.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
  #5 (permalink)  
Old October 18th, 2007, 08:29 AM
Registered User
 
Join Date: Aug 2007
Location: , , .
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Joe & Michael,
Fantastic stuff, the "apply-templates select="crs_content" worked a treat. Thanks, so much for you help.

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
xsl:copy-of Issue DKatSSA BOOK: XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition ISBN: 978-0-470-19274-0 8 November 19th, 2008 05:18 PM
performance issue with the xsl given here anboss XSLT 11 July 16th, 2008 03:05 AM
xsl:sort and IE 5.0 Issue babloo81 XSLT 1 March 17th, 2004 06:12 AM
Tricky Javascript/XSL issue...Hmmmm robster XSLT 1 January 23rd, 2004 11:28 AM
XSL Transform with xsl string NOT xsl file skin XSLT 0 June 16th, 2003 07:30 AM



All times are GMT -4. The time now is 10:35 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.