Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XSL to display an image

Status
Not open for further replies.

flyclassic22

Technical User
Oct 1, 2002
54
SG
Hi, I would like to ask how to display an image with XSL from a xml file which content the tag
<image1>abc.gif</image1>

i know about
<image><xsl:attribute name=&quot;src&quot;><xsl:value-of select=&quot;//image1&quot;/></xsl:attribute></image>

but can i do any conditional statement to display the image only when the <image1> tag content values.
I mean let say my particular xml file does not contain any image in <image1> tag, it will have a broken link in that xsl. So is there anyway to avoid it.

Or is there any conditional statement that could detect if the <image1> tag exist before displaying? (this will be great for me)

Thanks alot
Regards..

 
<xsl:template match=&quot;image1&quot;>
<xsl:if test=&quot;.!=''&quot;>
<img src=&quot;{.}&quot;/>
</xsl:if>

Build web applications faster with a few lines of XML Code using DataML[tm]
 
hi, i don't quite understand, can you elaborate ?
sorry, i'm stupid
 
This will ignore an empty tag...

<xsl:choose>
<xsl:when test=&quot;image1!=''&quot;>
<img>
<xsl:attribute name=&quot;src&quot;>
<xsl:value-of select=&quot;//image1&quot;/>
</xsl:attribute>
</img>
</xsl:when>
<xsl:eek:therwise/>
</xsl:choose>

Whichman's example checks for the existence of image1 an if it &quot;is not equal to nothing&quot; then write the tag where {.} is its value.
 
hi, it can't work, it says &quot;line 64, char 1 , expected eof found '!='
image-->!=<=--&quot;


---my script---
<?xml version=&quot;1.0&quot;?>
<xsl:stylesheet version=&quot;1.0&quot;
xmlns:xsl=&quot;
<xsl:template match=&quot;/&quot;>

<html>
<body bgcolor=&quot;#cccccc&quot;>
<xsl:for-each select=&quot;content&quot;>


<xsl:choose>
<xsl:when test=&quot;image!=''&quot;>
<img>
<xsl:attribute name=&quot;src&quot;>
<xsl:value-of select=&quot;//image&quot;/>
</xsl:attribute>
</img>
</xsl:when>
<xsl:eek:therwise/>
</xsl:choose>


</xsl:for-each>
</body>
</html>
</xsl:template>

</xsl:stylesheet>


anybody can help?
 
Is your element named 'image' or 'image1'. This doesn't need to be so complicated.

<xsl:if test=&quot;image1&quot;>
<img src={} etc etc
</xsl:if>

 
image1 or image doesn't matter i know what to do as i changed the tag
, ... mr grey,
yeah, yours is easy, but did you consider if there's no data in the image1 tag? there will be broken link when displayed.
 
can anyone explains this

hi, it can't work, it says &quot;line 64, char 1 , expected eof found '!='
image-->!=<=--&quot;
 
Hey one possible solution is to use the reverse test, and check to see if image contains &quot;.gif&quot; or &quot;.jpg&quot; or whatever your format is. I will look at your code closely when I get home and post a follow up as to why you are seeing that error, sorry I can't take the time to do it right now :)

Hope this helps a bit.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top