Solved

Including an image tag in XSL

Posted on 2012-04-11
4
336 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
  • 2
  • 2
4 Comments
 
LVL 23

Accepted Solution

by:
basicinstinct earned 500 total points
Comment Utility
<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
Comment Utility
Pefect thanks
0
 
LVL 23

Expert Comment

by:basicinstinct
Comment Utility
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
Comment Utility
Thank you very much - thats greatly appreciated.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

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 …
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

743 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now