XSLT default value

I've had it with this stupid language. How hard can it be to specify a default value for an attribute? It's frustrating beyond compare. Bah.

Anyway, I have a node. This node may or may not have an attribute called "render". When there is no such attribute, I want my to output "true", when there I have this attribute, I want to output its value.

I came up with something like this:

"render" : "<xsl:apply-templates select="list/entity/@render" mode="renderAttribute"/>"

Open in new window

and the template is:

    <xsl:template  name="renderAttribute">
        <xsl:when test="">
          <xsl:value-of select="true" />
          <xsl:value-of select="." />

Open in new window

Except it doesn't work. How do I make it work?
Who is Participating?
Geert BormansConnect With a Mentor Information ArchitectCommented:
as a defence to the language (which I don't consider "stupid") I see some sources of misunderstanding in your code,
so reading through an instructive book would not hurt your evolution in liking the language

well, the template will not fire for four reasons
- apply-template pushes out nodes to the templates with a @match, not to named templates
- the @mode you have does not correspond with the one (empty or default in the template
- for calling a named template (one with an attribute "name" instead of "match") you need call-template
- if you apply template with a potential empty node, nothing will happen

this is what I would do

"render" : "<xsl:apply-templates select="list/entity" mode="renderAttribute"/>"
and then

<xsl:template  match="entity[@render]" mode="renderAttribute">
  <xsl:value-of select="@render"/>

<xsl:template  match="entity[not(@render)]" mode="renderAttribute">
Geert BormansInformation ArchitectCommented:
and if you are willing to invest in your relation with the language

this one is a very good learning book
the latest edition also covers XSLT2
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.