jayce103 Posted January 30, 2009 Share Posted January 30, 2009 Hi all, I know that this topic has been covered before, but if some guru could find the time to help me that would be great...The problem I have is that I wish to show images located in a folder on my site, via xml. The image is linked through xml so that it appears (is this the right/best way?).When I open the webpage all the date is imported in, but the image has text (images/image1.jpg) etc. I am using xslt to style/translate the xml so what am I doing wrong?Thanks for your help people.footnote: are there any tutors/experts in the North West England area willing to help. Link to comment Share on other sites More sharing options...
real_illusions Posted January 30, 2009 Share Posted January 30, 2009 Post your code your using, and what is outputted to the browser. Link to comment Share on other sites More sharing options...
jayce103 Posted January 30, 2009 Author Share Posted January 30, 2009 This is the xml code<item> <title>Ming Vase</title> <author>ming</author> <image><a href="images/image1.jpg/></image> <colour>white with blue</colour> <description>Dated around 1925, no cracks or marks, in good condition</description> <year>1925</year> <price>450.00</price> </item>This is the xslt<?xml version="1.0" encoding="ISO-8859-1"?><xsl:stylesheet version="1.0"xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:template match="/"> <html><body> <h1>My CD Collection</h1><hr/> <xsl:for-each select="antiques/item"> <ul> <li><xsl:value-of select="title"/></li> <li><xsl:value-of select="author"/></li> <li><xsl:value-of select="image"/></li> <li><xsl:value-of select="description"/></li> <li><xsl:value-of select="year"/></li> <li><xsl:value-of select="price"/></li> </ul><hr/></xsl:for-each> </body> </html></xsl:template></xsl:stylesheet>the output in the browser is good except the line where the image should be is blankCheers,Jayce Link to comment Share on other sites More sharing options...
jesh Posted January 30, 2009 Share Posted January 30, 2009 I'm guessing this is just a copy/paste bug in the forum here, but there's a quote missing in the XML: <image><a href="images/image1.jpg/></image> Also, if this is the XSL for the image: <li><xsl:value-of select="image"/></li> Then maybe the XML should be more like this: <image><a href="images/image1.jpg"><img src="images/image1.jpg" /></a></image> Link to comment Share on other sites More sharing options...
packedpluto Posted February 24, 2009 Share Posted February 24, 2009 Here is what I did to get my images to show up using xml styled with xslt and displayed using php.XML file: <parent> <child> <src>/sample.jpg</src> </child></parent> and then the part of the xsl file that includes the image: <xsl:element name="img"> <xsl:attribute name="src"><xsl:value-of select="src"/></xsl:attribute> <xsl:attribute name="class">pic</xsl:attribute> <xsl:attribute name="alt">Sample Image</xsl:attribute></xsl:element> And then the php file that puts it all together: <?php include("header.php"); ?><?php// Load the XML source$xml = new DOMDocument;$xml->load('sample.xml');$xsl = new DOMDocument;$xsl->load('sample.xsl');// Configure the transformer$proc = new XSLTProcessor;$proc->importStyleSheet($xsl); // attach the xsl rulesecho $proc->transformToXML($xml);?><?php include("footer.php"); ?> I changed filenames, and simplified the xml tree for anonymity. Hope this helps you!If you have any other questions ask away! However, I am just a rookie at this stuff... But that code worked for me! Link to comment Share on other sites More sharing options...
boen_robot Posted February 24, 2009 Share Posted February 24, 2009 Alternatively to what packedpluto uses, you could have just <img src="{src}" alt="{alt}" /> (it's called AVT. See the XSLT FAQ for details on that one)or, to fit into your existing code, it would be more like: <li><img src="{image/a/@href}"/></li> or perhaps your desired result to have a copy of the link there? Like so? <li><xsl:copy-of select="image/a" /></li> Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.