Guest Jinxx Posted October 24, 2006 Share Posted October 24, 2006 Hi, I'm new to xslt, so please bear with me.... I was trying to get the template to check if a thumbnail image was available, and if so display that, otherwise use the original image. The thumbnails are in a separate directory (images\thumbs) and the full-sized images are just in images.what I have tried is:<img> <xsl:variable name="imageName"> <xsl:value-of select="image" /> </xsl:variable> <xsl:choose> <xsl:when test="images/thumbs/$imageName"> <xsl:attribute name="src"><xsl:value-of select="image" /></xsl:attribute> </xsl:when> <xsl:otherwise> <xsl:attribute name="src"><xsl:value-of select="image" /></xsl:attribute> </xsl:otherwise> </xsl:choose></img>I've gotten the images to work if I just have <xsl:attribute name="src"><xsl:value-of select="image" /></xsl:attribute> but I only want that to happen if there are no thumbs.Any help is greatly appreciated. Thank you in advance. Link to comment Share on other sites More sharing options...
boen_robot Posted October 24, 2006 Share Posted October 24, 2006 A simple <img><xsl:attribute name="src"><xsl:choose><xsl:when test="images/thumbs/image"><xsl:value-of select="image" /></xsl:when><xsl:otherwise>default-picture.jpg</xsl:otherwise></xsl:choose></xsl:attribute></img> Would do it. I mean, the node test checks if there is an <image> element on that position.But wait... what type of structure is your XML? What I'm showing works with something like for example <images><image><full>picture.jpg</full><thumb>picture-tb.jpg</thumb></image>...</images> But if I'm understanding correctly, your structure might be something like <images><full><image>picture.jpg</image>...<full><thumbs><image>picture-tb.jpg</image>...</thumbs></images> If so, then, do you at least have some IDs on the images? I mean, if not everyone has a thumb, this is a good to have. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now