By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,483 Members | 1,039 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,483 IT Pros & Developers. It's quick & easy.

I want to display images using xslt. How can i do this? Not familliar with XSLT

P: 4
I've converted the rest response to xml.
Here's my xml:

Expand|Select|Wrap|Line Numbers
  1. <Result>
  2.    <DressPrice>
  3.       <Name>Dress 2</Name>
  4.       <Price>20</Price>
  5.       <Image>2.jpeg</Image>
  6.    </DressPrice>
  7.    <DressPrice>
  8.       <Name>Dress 9</Name>
  9.       <Price>20</Price>
  10.       <Image>3.jpeg</Image>
  11.    </DressPrice>
  12.    <DressPrice>
  13.       <Name>Dress 10</Name>
  14.       <Price>20</Price>
  15.       <Image>0905C58A0179_1.jpeg</Image>
  16.    </DressPrice>
  17.    <DressPrice>
  18.       <Name>Dress 11</Name>
  19.       <Price>20</Price>
  20.       <Image>0905C58A0179_1.jpeg</Image>
  21.    </DressPrice>
  22.    <DressPrice>
  23.       <Name>Dress 12</Name>
  24.       <Price>20</Price>
  25.       <Image>0905C58A0179_1.jpeg</Image>
  26.    </DressPrice>
  27. </Result>
My current XSLT:

Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="UTF-8"?>
  2.  
  3. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  4.     <xsl:strip-space elements="*" /> 
  5.     <xsl:template match="/">
  6.         <html>
  7.             <head><title>Dresses Per Price</title>
  8.             <link rel="stylesheet" type="text/css" href="price.css"/>
  9.             </head>
  10.             <body>
  11.                 <h3>Dresses Per Price Displayed</h3>
  12.                 <table border="1">
  13.                     <thead>
  14.                         <tr style="background-color:PaleGreen;"><th>Name</th><th>Price</th><th>Image</th></tr>
  15.                     </thead>
  16.                     <tbody>
  17.                         <xsl:for-each select="Result">
  18.                             <xsl:apply-templates>
  19.                                 <xsl:sort select="Name" data-type="text" order="ascending"/>
  20.                             </xsl:apply-templates>
  21.                         </xsl:for-each>
  22.                     </tbody>
  23.                 </table>
  24.                 <p><strong>Note:</strong>Data listed above may not reflect the current state</p>
  25.             </body>
  26.         </html>
  27.     </xsl:template>
  28.     <xsl:template match="DressPrice">
  29.         <xsl:variable name="cssClass">
  30.             <xsl:choose>
  31.                 <xsl:when test="position() mod 2 = 0">coloured</xsl:when>
  32.                 <xsl:otherwise>normal</xsl:otherwise>
  33.             </xsl:choose>
  34.         </xsl:variable>
  35.         <tr class="{$cssClass}">
  36.             <xsl:apply-templates select="Name"/>
  37.             <xsl:apply-templates select="Price"/>
  38.             <xsl:apply-templates select="Image"/>
  39.         </tr>
  40.     </xsl:template>
  41.     <xsl:template match="Name|Price|Image">
  42.         <td><xsl:value-of select="text()"/></td>
  43.     </xsl:template>
  44. </xsl:stylesheet>

Can someone please help me or point me in the right direction? Thanks
Apr 9 '15 #1
Share this Question
Share on Google+
7 Replies


Dormilich
Expert Mod 5K+
P: 8,639
I want to display images using xslt. How can i do this? Not familliar with XSLT
thatís not an XSLT issue, itís an HTML issue (because you generate HTML /1/).

to answer the question: use an <img> tag



/1/ itís like PHP, that doesnít display images either, it can only create the data for displaying an image.
Apr 9 '15 #2

P: 4
Thank you but can you show me how to use the <img> tag? Should it be added in the xslt?
Apr 9 '15 #3

Dormilich
Expert Mod 5K+
P: 8,639
where else do you create the HTML code?

about the img tag.
Apr 9 '15 #4

P: 4
Any hint where to place it?
Apr 9 '15 #5

Dormilich
Expert Mod 5K+
P: 8,639
in the Image template.

and, yes, that requires you to write a new template.
Apr 9 '15 #6

P: 4
Expand|Select|Wrap|Line Numbers
  1. <xsl:template match="Image">
  2.         <xsl:variable name="img">
  3.         <td><img src="{$img}"></img></td>
  4.         </xsl:variable>
  5.     </xsl:template>
This is what i tried so far but i'm getting an error. What did i do wrong? And thanks for your precious time.
Apr 9 '15 #7

Dormilich
Expert Mod 5K+
P: 8,639
What did i do wrong?
what does the error say?
Apr 9 '15 #8

Post your reply

Sign in to post your reply or Sign up for a free account.