Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Amir Khan 1199 posts 2567 karma points
    Sep 13, 2011 @ 21:20
    Amir Khan
    0

    XSL:Choose always returning null

    Hi,

    I'm using the following xsl:choose statement to check for the "metaTItle" field in my master document type, it is constantly returning null. Am I missing something?


    Thanks!

    Amir

    <xsl:choose>
    <xsl:when test="$currentPage/data[@alias='metaTitle'] != 0">
      Hello!
     </xsl:when>
     <xsl:otherwise>
      Goodbye!
     </xsl:otherwise>
    </xsl:choose>
  • Amir Khan 1199 posts 2567 karma points
    Sep 13, 2011 @ 21:38
    Amir Khan
    0

    Got it!

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <xsl:stylesheet
      version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:msxml="urn:schemas-microsoft-com:xslt"
      xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets"
      exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">


    <xsl:output method="xml" omit-xml-declaration="yes"/>

    <xsl:param name="currentPage"/>

    <xsl:template match="/">
    <xsl:variable name="metaTitleValue" select="umbraco.library:Item($currentPage/@id, 'metaTitle')" />

    <!-- start writing XSLT -->
    <xsl:choose>
      <xsl:when test="$metaTitleValue != ''">
        <xsl:value-of select="$currentPage/metaTitle"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$currentPage/@nodeName"/>
      </xsl:otherwise>
    </xsl:choose>
     
    </xsl:template>

    </xsl:stylesheet>
  • Chriztian Steinmeier 2726 posts 8320 karma points MVP 4x admin c-trib
    Sep 13, 2011 @ 21:59
    Chriztian Steinmeier
    1

    Hi Amir,

    If you want to be absolutely positively sure that there's nothing useful in the field, use the normalize-space() function:

    <xsl:when test="normalize-space($metaTitleValue)">

    - and if you want to do it all on one line (take metaTitle but fall back to @nodeName if empty):

    <xsl:value-of select="($currentPage/@nodeName[not(normalize-space(../metaTitle))] | $currentPage/metaTitle)[1]">

    /Chriztian

  • Amir Khan 1199 posts 2567 karma points
    Sep 19, 2011 @ 16:13
    Amir Khan
    0

    Thanks Chriztain!

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies