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

Discussion in 'XML' started by Michael Ahlers, Jul 12, 2004.

  1. 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.)
    Michael Ahlers, Jul 12, 2004
    #1
    1. Advertising

  2. Re: Easy way to output a default value if <xsl:value-of/> selectioncomes back empty?

    Michael Ahlers wrote:

    > 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/.

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Jul 12, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    2
    Views:
    1,716
    Thomas
    Jan 26, 2005
  2. Cindy Hunt
    Replies:
    0
    Views:
    499
    Cindy Hunt
    Sep 23, 2003
  3. Soren Kuula
    Replies:
    2
    Views:
    548
    Malcolm Dew-Jones
    Apr 13, 2005
  4. C Gillespie
    Replies:
    3
    Views:
    396
    Peter Hansen
    Mar 22, 2005
  5. JJ297
    Replies:
    1
    Views:
    505
    sloan
    Jan 15, 2008
Loading...

Share This Page