?
Solved

Including an image tag in XSL

Posted on 2012-04-11
4
Medium Priority
?
393 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 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

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

The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
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…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses
Course of the Month17 days, 6 hours left to enroll

864 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