Forum Moderators: open

Message Too Old, No Replies

Inserting images using XSLT

Inserting images using XSLT

         

rainmaker32

2:08 am on Sep 17, 2005 (gmt 0)

10+ Year Member



Hello all, quick question. I am transitioning our web content into xml files. I am able to use xslt to transform all of our stored content except our images.

I keep the path to the image in the xml file like this:

<top_photo1>/website/images/ExtView3.jpg</top_photo1>

and I am not sure what xslt syntax to use to transform it into the appropriate html i.e.:
<img style="float:left; margin-right:0px; margin-bottom:0px" src="/website/images/ExtView3.jpg" alt="=" title="Home" />

Currently I have tried many variations of this but none work:
<xsl:template match="/">
...
<img stlye="float:left; margin-right:0px; margin-bottom:0px" src="{top_photo1}" alt="=" title="Home" />
...
</xsl:template>
</xsl:transform>

Please note, all my other data transforms perfectly just not the images.

**Any pointers would be greatly appreciated.

GordonS

6:54 pm on Sep 18, 2005 (gmt 0)

10+ Year Member



It looks OK to me but it is probably a issue with the image src tag.

When you run the transform in your web browser and examine the HTML source that is generated, what is the URL to the image in the img src tag?

Is the src tag completely empty, or does it have a duff URL?

If empty, I'd suggest playing about with the XPATH in your <xsl:template match="/"> or possibly trying a syntax like this until you isolate the problem:

<img style="..." alt="="><xsl:attribute name="src"><xsl:value-of select="//top_photo1" /></xsl:attribute></img>

choster

11:03 pm on Sep 19, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What is the structure of your XML? With {top_photo1} you are requesting the text content of a child of the current node named <top_photo1>; however, your template is matching on the root (/) so you will almost certainly be getting null.

If for example your XML looked like

<article>
<date>19 Sep 2005</date>
<header>
<top_photo1>/website/images/ExtView3.jpg</top_photo1>
<author>Jane Doe</author>
</header>
<body>
<p>Main body of the article here.</p>
</body>
</article>

you could write

<xsl:template match="/">
...
<img style="float:left; margin-right:0px; margin-bottom:0px" src="{article/header/top_photo1}" alt="" title="Home" />
...
</xsl:template>

or for more flexibility perhaps

<xsl:template match="/">
<xsl:apply-templates />
</xsl:template>
...
<xsl:template match="header">
<img style="float:left; margin-right:0px; margin-bottom:0px" src="{top_photo1}" alt="" title="Home" />
</xsl:template>
...

rainmaker32

12:46 am on Sep 24, 2005 (gmt 0)

10+ Year Member



Sorry guys I was out of town for the week. I will experiment with your suggestions and post up the results.

Thanks!