[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Adding child rows to a table using XSL

Posted on 2012-04-11
4
Medium Priority
?
324 Views
Last Modified: 2012-06-27
I am currently transforming XML into an HTML table using XSL.

The XML file is a collection of 'Roads' - which I am rendering out to a table.

XML: http://sandbox5.project4.net/child/roads_locs.xml
XSL: http://sandbox5.project4.net/child/roads.xsl
HTML Output: http://sandbox5.project4.net/child/default.asp

You may note in the XSL that some roads may have one or more child 'locations'.

Question: How can I modify my XSL to show 'location' information below each road row?
0
Comment
Question by:sonic1234
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 2000 total points
ID: 37836398
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output omit-xml-declaration="yes" method="html"/> 
<xsl:template match="roads">
   
            <table class="table-j" summary="Road Closures">
               <thead>
                  <tr>
                     <th scope="col">Road Name</th>
                     <th scope="col">Council</th>
                     <th scope="col">Status</th>
                     <th scope="col">Last Updated</th>
                     <th scope="col">Last Observed</th>
                  </tr>
               </thead>
                  <tfoot>
                  <tr>
                     <td colspan="5"><em>As road conditions are constantly changing, the information shown above may not represent the actual road condition. Please drive with caution at all times.</em></td>
                  </tr>
               </tfoot>
               <tbody>
                  <xsl:apply-templates select="road"/>
               </tbody>
            </table>

    </xsl:template>
   
   <xsl:template match="road">
      <tr>
         <td>
            <b><xsl:value-of select="name"/></b>
         </td>
         <td>
            <xsl:value-of select="org"/>
         </td>
         <td>
            <xsl:value-of select="status"/>
         </td>
         <td>
            <xsl:value-of select="observed"/>
         </td>
         <td>
            <xsl:value-of select="updated"/>
         </td>
      </tr>
      <xsl:apply-templates select="locations/location"></xsl:apply-templates>
   </xsl:template>
   
   <xsl:template match="location">
      <tr>
         <td>
            <i><xsl:value-of select="name"/></i>
         </td>
         <td>
            <xsl:value-of select="org"/>
         </td>
         <td>
            <xsl:value-of select="status"/>
         </td>
         <td>
            <xsl:value-of select="observed"/>
         </td>
         <td>
            <xsl:value-of select="updated"/>
         </td>
      </tr>
   </xsl:template>
</xsl:stylesheet>

Open in new window

0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 37836401
Note that I slightly restructured your original stylesheet to use apply-templates in favour of for-each.
It greatly improves  the readibility and maintainability of your stylesheet
You pass the child nodes to a different template

Then you simply do the same with the location nodes

I made the road names bold so you see the difference
0
 

Author Closing Comment

by:sonic1234
ID: 37840906
Thank you Gertone, that is very clear and helpful.
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 37841309
welcome
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question