Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Including an image tag in XSL

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
Create a Windows 10 custom Image with custom task bar and custom start menu using XML for deployment.
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

610 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