Easy way to output a default value if <xsl:value-of/> selection comes back empty?

M

Michael Ahlers

I am looking for a way to get my transformations to output a default
value from <xsl:value-of/> if a selected element doesn't exist or is
empty without having to have tons and tons of <xsl:choose/> blocks
everywhere. Is there a quick solution to this or am I going to have
to take the pain? (Also, suggestions on where else I should post this
question would be helpful.)
 
M

Martin Honnen

Michael said:
I am looking for a way to get my transformations to output a default
value from <xsl:value-of/> if a selected element doesn't exist or is
empty without having to have tons and tons of <xsl:choose/> blocks
everywhere.

I think you need xsl:choose. Or write a named template that you call
(which of course in its body then has xsl:choose).
Is there a quick solution to this or am I going to have
to take the pain?

XPath 2.0 might make that easier as I think there you can write some if
expression alike
<xsl:value-of select="if (text()) then text() else 'Maho'" />
You can try XSLT 2.0/XPath 2.0 with Saxon from http://saxon.sf.net/.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top