Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 26th, 2008, 01:38 PM
Registered User
 
Join Date: Aug 2007
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default xslt problem

Hi, I am having problem bolding text inside an unordered list. The xslt uses the <strong> tag template correctly except inside the <li> tag. When I include a <strong> tag inside the[list]<li> for loop the text doen't get displayed.

Here is my XML

<course num="17">
<crs_no>17</crs_no>
<crs_title>English literature</crs_title>
<crs_places>81</crs_places>
<crs_details>
<h5>The Freshman years</h5>
<p>Over the <strong>Junior and Senior Freshman</strong> (first two) years a range of courses provides you with an introduction to a variety of critical theories, practices and approaches to literature. You will primarily concentrate on selected prescribed texts, which include the following:</p>[list]
<li>Critical and Cultural Theory - an introduction to the elements of critical theory, to the varieties of criticism, and to the relation of literary study to the more general field of cultural practices.</li>
<li><strong>Literature and english</strong>- after an introduction to theories of english, this course focuses on certain aspects of the topic arising in 19th and 20th century fiction.</li>
<li><strong>Romanticism and revolutions</strong>- a course concerned with a range of writing for the <strong>Romantic period</strong>, both in prose and poetry, and with the changing cultural contexts out of which it emerged.
</li>
</course>


Here is my XSL


<?xml version="1.0" encoding='UTF-8'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:variable name="empty_string"/>
<xsl:variable name="tsmcode">TR001</xsl:variable>
<xsl:param name="p_crs_id"></xsl:param>
<xsl:param name="p_contactemail"></xsl:param>
<xsl:template match="courses/course">

  <xsl:if test="crs_no=$p_crs_id">

    <div id="rightColumn">
    <div class="rightcontainerNews">
    [list]<li><span><a href="#">How to Apply</a></span></li>
        <li><span><a href="#" class="on">Admission Requirements</a></span></li>
    </ul>
      <xsl:apply-templates select="academic_units"/>
      <xsl:if test="crs_image != $empty_string">
         <img class="academic-unit" src="{crs_image}" alt="Course Image" height="132" width="176" />
     </xsl:if>
    </div>
     </div>



  <div class="coursedetails">
  <h3 class="courseheading"><xsl:apply-templates select="crs_title"/></h3>
    [list]
      <li><span><strong>Course Type:</strong></span>
        <xsl:apply-templates select="crs_type_name"/>
      </li>
          <xsl:if test="cao_code != $empty_string">
        <li><span><strong>Course Code: </strong></span>
          <xsl:apply-templates select="cao_code"/>
        </li>
      </xsl:if>
        <xsl:if test="crs_places != $empty_string">
        <li><span><strong>No. Of Places: </strong></span>
          <xsl:apply-templates select="crs_places"/>
        </li>
      </xsl:if>
        <xsl:if test="cao_points != $empty_string">
        <li><span><strong>Min Entry Points <xsl:apply-templates select="cao_points_year"/></strong>:</span>
          <xsl:apply-templates select="cao_points"/> points
        <xsl:if test="cao_code=$tsmcode"><a href="#" target="_new"> (Points per TSM combination)</a></xsl:if>
        </li>
      </xsl:if>
            <xsl:if test="crs_duration != $empty_string">
        <li><span><strong>Duration:</strong></span>
          <xsl:apply-templates select="crs_duration"/>

          <xsl:choose>
            <xsl:when test="crs_ft_pt='1'">
              Full Time
            </xsl:when>
            <xsl:otherwise>
              Part Time
            </xsl:otherwise>
          </xsl:choose>
        </li>
      </xsl:if>
      <xsl:if test="crs_letters != $empty_string">
        <li><span><strong>Award: </strong></span>
          <xsl:apply-templates select="crs_letters"/>
        </li>
      </xsl:if>

      <xsl:if test="crs_special_entry != $empty_string">
         <li><span><strong>Specific Entry Requirements: </strong></span><a href="#requirements">See bottom of this page</a></li>
      </xsl:if>

      <xsl:if test="crs_restricted_entry != $empty_string">
        <li><span><strong>Restricted Entry: </strong></span><xsl:apply-templates select="crs_restricted_entry"/></li>
      </xsl:if>

      <xsl:if test="crs_options != $empty_string">
        <li><span><strong>Course Options: </strong></span><xsl:apply-templates select="crs_options"/></li>
      </xsl:if>

    </ul>
    </div>

    <p><xsl:apply-templates select="crs_details"/></p>

    <xsl:if test="crs_special_entry != $empty_string">
         <a id="requirements"><p><xsl:apply-templates select="crs_special_entry"/></p></a>
    </xsl:if>

    <xsl:if test="crs_grad_profile != $empty_string">
        <p><xsl:apply-templates select="crs_grad_profile"/></p>
    </xsl:if>


    <div id="schoolFooter">
    <span class="cloak">|</span>
    <a href="mailto:{$p_contactemail}" class="mail"><xsl:value-of select="$p_contactemail"/></a>
    <span class="cloak">|</span>
    <span class="date">Last Updated: <xsl:apply-templates select="last_updated"/></span>
    </div>


  </xsl:if>
</xsl:template>

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

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

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

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

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

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

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

  <xsl:template match="image">
  <img src="{@src}" alt="{@alt}"/>
  </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="academic_units">
     <ul class="academic-structure">
       <xsl:for-each select="unit">
             <li><a href="{au_url_ug}"><xsl:apply-templates select="au_long_name"/></a></li>
       </xsl:for-each>
     </ul>
  </xsl:template>

  <xsl:template match="crs_special_entry">
    <h4>Specific Entry Requirements</h4>

    <div class="tablecontainer">
    <table summary="Course Specific Entry Requirements">
    <xsl:for-each select="special_entry">
        <tr><td><strong><xsl:apply-templates select="criteria"/></strong></td>
            <td><xsl:apply-templates select="requirement"/></td>
        </tr>
    </xsl:for-each>
    </table>
    </div>
  </xsl:template>

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

</xsl:stylesheet>

 
Old March 26th, 2008, 04:25 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

There's an awful lot of extraneous detail here. Please cut it down to the part of the source document and the part of the stylesheet that demonstrates the problem. Then show the output you are getting and the output that you wanted to get (as source HTML markup, not as it appears in the browser.)

If you do this you may even find the answer yourself.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old March 26th, 2008, 06:15 PM
Friend of Wrox
 
Join Date: Jul 2006
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
Send a message via Yahoo to bonekrusher
Default

Hi,

For starters your xml sample is not well formed.

I believe you need to change:

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


to:
Code:
    <xsl:template match="ul">
        [list]
            <xsl:for-each select="li">
                <li>
                    <xsl:apply-templates/>
                </li>
            </xsl:for-each>
        </ul>
    </xsl:template>


<xsl:value-of select="text()"/> only will output the text of the element, so <xsl:apply-templates/> will apply all the templates for <li> children.

HTH

Bones


 
Old March 28th, 2008, 05:09 AM
Registered User
 
Join Date: Aug 2007
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Bones,
 <xsl:apply-templates/> worked a treat

Thanks very much,
Mick






Similar Threads
Thread Thread Starter Forum Replies Last Post
XSLT problem with IE 7 asadallahi BOOK: Professional Ajax ISBN: 978-0-471-77778-6 3 April 9th, 2009 09:33 AM
XSLT problem her_today XSLT 1 October 23rd, 2006 11:09 AM
dynamic xslt -> xslt creation namespace problem jkmyoung XSLT 2 July 15th, 2006 12:42 AM
XSLT problem pendyalap XSLT 4 March 24th, 2006 04:08 PM
problem with xslt superwebba BOOK: Professional Ajax ISBN: 978-0-471-77778-6 5 March 10th, 2006 01:31 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.