Forum Moderators: open

Message Too Old, No Replies

XML Variables into templates

Making an image path element into a variable

         

Barbacena

5:15 pm on May 19, 2006 (gmt 0)

10+ Year Member



Hi all, I wrote a post (which wasn't properly explained I think) here a few months ago but really didn't have time to go through the response as I had to leave the job on hold even if someone kindly posted in reply and now it is too old for me to be able to reply to it.

Basically I have a template which goes as follows:

<images>
<image>
<id>001</id>
<name>Image 1</name>
<caption>Some text describing this image</caption>
<url color={$WhichColor}>image1.png</url>
</image>
</images>

Now, in my XSL document I wanted a global variable that will set up the root for all images in my site.

<xsl:variable name="Root" select="images/" />

Then I wanted a variable which will pic up the root for all images in that section of the site:

<xsl:variable name="MyImages" select="colorschemes/" />

Finally I wanted another variable which will select a particular color for this page of the site

<xsl:variable name="WhichColor" select="" />

I would like to set up this last variable to nothing so that for each page I could write something along the lines of "red/myimagename.png", "blue/myimagename.png" etc.

All images have the same name, the only thing that is different about them is the color directory.

Then I need to somehow pass this together with my image name as an alt tag into the <img> tag.

I was thinking of something like:

<xsl:template match="images/">
<xsl:for-each select="image">
<img src="{$Root}{$MyImages}<xsl:value-of select="WhichColor" /><xsl:value-of select="url" />" alt="<xsl:value-of select="url" />">
</xsl:for-each>
</xsl:template>

I don't know much about the XML syntax and this is obviourly very wrong, how do I output that into an image tag with a flexible WhichColor variable output?

I hope that I have explained myself correctly this time!

Thank you!

choster

6:07 pm on May 24, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It's a little hard to make out what you're trying to do. You refer to the text at the top as your template, but it looks more like your desired output. Can you post a relevant section of your input XML (i.e. containing <images> and <colorschemes>) and what output you're trying to achieve?

Just as an observation, you have some invalid syntax (e.g. {$WhichColor} must be quoted, and XPath cannot end with a trailing slash), so a good XPath reference may be in order.