?
Solved

Including an image tag in XSL

Posted on 2012-04-11
4
Medium Priority
?
384 Views
Last Modified: 2012-04-11
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/icon/roads_locs.xml
XSL: http://sandbox5.project4.net/icon/roads.xsl
HTML Output: http://sandbox5.project4.net/icon/default.asp

You may note in the XSL that I have an <icon> property for each <road> element

Question: How can I modify my XSL to output an <img src=""> tag that includes the 'icon' property for each road

I have tried something like the below - but I know line 23 is not right as the XSL throws an error

<xsl:template match="roads">
   
            <table class="table-j" summary="Road Closures">
               <thead>
                  <tr>
                     <th scope="col">Status</th>
                     <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:for-each select="road">
                  <tr>
                     <td>
                         <img src="<xsl:value-of select="icon"/>">
                     </td>
                     <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:for-each>
               </tbody>
            </table>

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

Open in new window

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
  • 2
  • 2
4 Comments
 
LVL 23

Accepted Solution

by:
basicinstinct earned 2000 total points
ID: 37836053
<td>
            <xsl:element name="img">
               <xsl:attribute name="src"><xsl:value-of select="icon"/></xsl:attribute>
            </xsl:element>
         </td>
0
 

Author Closing Comment

by:sonic1234
ID: 37836061
Pefect thanks
0
 
LVL 23

Expert Comment

by:basicinstinct
ID: 37836071
btw looping thru the elements with an xsl:for-each is not best practice and gives bad code and bad performance.

I started a rewrite to get you on the right track. It is attached.
roads.xsl
0
 

Author Comment

by:sonic1234
ID: 37836078
Thank you very much - thats greatly appreciated.
0

Featured Post

Quick Cloud Training

Looking for some quick training on the cloud in 2 hours or less? Check out these how-to guides in AWS, Linux, OpenStack, Azure, and more!

Question has a verified solution.

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

The Problem How to write an Xquery that works like a SQL outer join, providing placeholders for absent data on the outer side?  I give a bit more background at the end. The situation expressed as relational data Let’s work through this.  I’ve …
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses
Course of the Month12 days, 20 hours left to enroll

777 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