Solved

Including an image tag in XSL

Posted on 2012-04-11
4
370 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 500 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

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…
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

749 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