Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8940951
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:10:49+00:00 2026-06-15T11:10:49+00:00

I’ve started playing around with XSLT, and am having a few issues. I’ve managed

  • 0

I’ve started playing around with XSLT, and am having a few issues. I’ve managed to output my XML document using a series of value-of select instructions, but I’m really struggling when it comes to writing my XSLT templates myself.

Here’s my XML:

<?xml version="1.0" ?>
<?xml-stylesheet type="text/xsl" href="lecturers.xsl"?>
<lecturers>
<lecturer>
        <name> 
             <title>Professor</title> 
        <first>Peter </first> <last>Quirk</last>
        </name>
        <teaching>
        <course code="CO3070">XML and the Web</course>
        <course code="CO3300"> Web Server Architectures</course>
    </teaching>
    <research>
        The application of Web protocols to Biology
    </research>
</lecturer>

<lecturer>
    <name> 
    <title>Doctor</title> 
    <first>Brian </first> <last>Johnson</last>
    </name>
    <teaching>
        <course code="CO9999">Computer Hacking</course>
        <course code="CO3300"> Web Server Architectures</course>
    </teaching>
    <research>
        Investigating the various complexities of Computer Hacking
    </research>
</lecturer>

Then, this is my XSL as it currently stands:

 <?xml version="1.0"?>
 <xsl:stylesheet version='1.0' xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output method="html" version="4.0" />

 <xsl:template match="/">
 <html>
 <head>
 <title>XML Week 7</title>
 </head>

  <body>
  <h1>Week 7: Lecturers file turned to XSL:Template</h1>

 <table border="1">
<tr>
    <th><b>Title</b></th>
    <th><b>Name</b></th>
    <th><b>Teaching</b></th>
    <th><b>Research</b></th>
</tr>

<tr>

    <td><xsl:value-of select="lecturers/lecturer/name/title" /></td>
    <td><xsl:value-of select="lecturers/lecturer/name/first" /><xsl:text>&#x20;</xsl:text><xsl:value-of select="lecturers/lecturer/name/last" /></td>
    <td><xsl:value-of select="lecturers/lecturer/teaching/course" /> and <xsl:value-of select="(lecturers/lecturer/teaching/course)[2]" /></td>
    <td><xsl:value-of select="lecturers/lecturer/research" /></td>

</tr>
 </table>

</body>

</html>
 </xsl:template>
 </xsl:stylesheet>

This does output the information I need into a table, but I’ve been instructed to create new templates to hold the lecturer element, and then the course children of that element. I might just be over-complicating things in my head, but I just cannot get it to work, whenever I try to apply a template to one of the td’s I just get a parsing error in the browser. So, does anyone have any tips for me? Would be much appreciated, even some basic examples to explain how to get it working in my example would be superb. Cheers guys.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T11:10:50+00:00Added an answer on June 15, 2026 at 11:10 am

    Use one template to create the result document structure e.g.

     <xsl:template match="/">
     <html>
     <head>
     <title>XML Week 7</title>
     </head>
    
      <body>
        <xsl:apply-templates/>
    
    </body>
    
    </html>
     </xsl:template>
    

    then write further templates to create the content e.g.

    <xsl:template match="lecturers">
      <h1>Week 7: Lecturers file turned to XSL:Template</h1>
    
     <table border="1">
    <tr>
        <th><b>Title</b></th>
        <th><b>Name</b></th>
        <th><b>Teaching</b></th>
        <th><b>Research</b></th>
    </tr>
      <xsl:apply-templates/>
    </table>
    </xsl:template>
    
    <xsl:template match="lecturer">
    <tr>
    
        <td><xsl:value-of select="name/title" /></td>
        <td><xsl:value-of select="name/first" /><xsl:text>&#x20;</xsl:text><xsl:value-of select="name/last" /></td>
        <td><xsl:value-of select="teaching/course" /> and <xsl:value-of select="(teaching/course)[2]" /></td>
        <td><xsl:value-of select="lecturers/lecturer/research" /></td>
    
    </tr>
    </xsl:template>
    

    As you see, the templates do an apply-templates to keep up the processing.

    [edit]
    In response to your comment, if you want to use more templates for the different child or descendant elements of the lecturer element you can use

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

    and then write templates for the elements e.g.

    <xsl:template match="name/title | research">
      <td>
        <xsl:value-of select="."/>
      </td>
    </xsl:template>
    
    <xsl:template match="name/first">
      <td>
        <xsl:value-of select="concat(., ' ', ../last)"/>
      </td>
    </xsl:template>
    
    <!-- don't output name/last as the name/first template already does -->
    <xsl:template match="name/last"/>
    
    <xsl:template match="teaching">
      <xsl:apply-templates select="course"/>
    </xsl:template>
    
    <xsl:template match="course">
      <xsl:if test="position() > 1"><xsl:text> and </xsl:text></xsl:if>
      <xsl:value-of select="."/>
    </xsl:template>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We are using XSLT to translate a RIXML file to XML. Our RIXML contains
link Im having trouble converting the html entites into html characters, (&# 8217;) i
We're building an app, our first using Rails 3, and we're having to build
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am reading a book about Javascript and jQuery and using one of the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.