<!-- Match anything that's not empty --> <xsl:template match="*[normalize-space()]" mode="comma"> <xsl:value-of select="."/>, </xsl:template>
<!-- Match empty elements (do nothing) --> <xsl:template match="*[not(normalize-space())]" mode="comma"/>
If you were doing different things with each element I'd reccomend you do one template for each of them, but since you are just writing out the text and a comma I tried just using one template.
Remove Comma from list if DocType property is absent.
Right I have a macro that display the description of an image. The problem is, not all the properties are mandatory and sometimes they are left blank.
Below I get the properties in a macro and seperate them with a comma (,).
Is there a way of removing the comma if a property is left blank?
<div class="description">
<span><xsl:value-of select="title"/>, <xsl:value-of select="year"/>, <xsl:value-of select="medium"/>, <xsl:value-of select="dimensions"/></span>
</div>
Thanks in advance
James
Cannt you use
<xsl:if test="CONDITION">
</xsl:if>
Hi James,
Yes, there's a few ways you could handle this. I think the below should work and is probably the best:
If you were doing different things with each element I'd reccomend you do one template for each of them, but since you are just writing out the text and a comma I tried just using one template.
Ex: <xsl:template match="title"><strong><xsl:value-of select="."/></strong>, </xsl:template>
-Tom
And as Anthony suggested wrapping each line in an IF statement would work too, I prefer something like the above though for cleanliness :)
Hey guys, thanks a bunch for your answers,
I went with the simplist option of:
<div class="description">
<span>
<xsl:value-of select="title"/>
<xsl:if test="year != ''">
, <xsl:value-of select="year"/>
</xsl:if>
<xsl:if test="medium != ''">
, <xsl:value-of select="medium"/>
</xsl:if>
<xsl:if test="dimensions != ''">
, <xsl:value-of select="dimensions"/>
</xsl:if>
</span>
</div>
This works fine.
Again, thanks!
is working on a reply...