PDA

View Full Version : images into html via xml


rr299
05-25-2007, 10:15 PM
Hi I hope someone can help me here. I have an xml document which has some text in it and some paths to images like the following:


<car>
<summary>here is a car</summary>
<model>this is the model</model>
<price>£xxxx</price>
<details>lots of cool features</details>
<thumbMain>stock/sl500/thumbMain.jpg</thumbMain>
</car>
etc...


I am using an xstl document to format the xml so i can show it in a table in a browser. This is all fine apart from when it comes to loading in the images. At the moment it is just loading the path text so I obviously need to process the information some how. Please can someone help, I have tried wrapping <img> tags around the path in the xstl but it isn't working. I can't find the answer anywhere which must mean i am searching for the wrong thing:(

Thanks

mr e
05-26-2007, 04:26 AM
I'm no XSLT guru, but wouldn't it be something more like

<img src="XSLT stuff" />

rr299
05-26-2007, 08:05 AM
yeah i think so but how do i wrap that around what i take from my xml. I don't want to have to change my xml as it is also used for soemthing else.

Clogs
05-26-2007, 03:07 PM
In your stylesheet simply place an <img> tag, then use attribute tags to select the required attributes: src, alt etc. and the normal value-of tag to pull the right data value from your XML.

In the example below for instance im setting the alt attribute of my image to be the data held by <description>data</description> tags in my xml. Im setting the src tag to be the values of my xsl text + data of the <name> tag + the data of the <type> tag.


Hope that helps.

<img>
<xsl:attribute name="alt">
<xsl:value-of select="description" />
</xsl:attribute>
<xsl:attribute name="src">
<xsl:text>http://www.mywebsite.com/~user/</xsl:text>
<xsl:value-of select="name" />
<xsl:value-of select="type" />
</xsl:attribute>
</img>

Clogs.