locked
XSLT string comparison RRS feed

  • Question

  • User1692533347 posted

    Hi

    I have follwoing code in XSLT file, i am trying to use if condition  but its not working, please help.

    <xsl:variable name="showNews">
    		<xsl:choose>
    			<xsl:when test="ddwrt:FormatDateTime(@ExpiryDate, 1033, 'dd MMMM yyyy') =''">
    				false
    			</xsl:when>
    		</xsl:choose>
    	</xsl:variable>
    	
    <xsl:if test="$showNews = 'false'"> <xsl:value-of select="$showNews"></xsl:value-of> </xsl:if> 
    
    
    <xsl:if test="$showNews = 'False'"> <xsl:value-of select="$showNews"></xsl:value-of> </xsl:if> 
    <xsl:if test="$showNews = false"> <xsl:value-of select="$showNews"></xsl:value-of> </xsl:if> 
    <xsl:if test="$showNews = False"> <xsl:value-of select="$showNews"></xsl:value-of> </xsl:if>
    

    it does'nt print anything in if condition, if i try to print $showNews, it returns false.

    Am i using the right way of string comparison?

    Tuesday, January 8, 2013 10:16 PM

Answers

  • User1546878023 posted

    You are probably facing issues with linespaces. Try writing

    <![CDATA[false]]>

    then you can use your string comparison.

    Otherwise you could also just write

    <xsl:variable name="showNews" select="ddwrt:FormatDateTime(@ExpiryDate, 1033, 'dd MMMM yyyy') =''/>

    And then you can write <xsl:if test="$showNews">

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, January 12, 2013 5:14 PM

All replies

  • User-1293249277 posted

    What is your input XML?

    Thursday, January 10, 2013 12:51 AM
  • User1692533347 posted

    I am using this XSLT code in sharepoint, can't put xml here.

    Thursday, January 10, 2013 4:23 AM
  • User3866881 posted

    I am using this XSLT code in sharepoint, can't put xml here.

    Hi,

    If you don't show us your full xml contents, I'm afraid we cannot continue to help you more.

    Friday, January 11, 2013 1:07 AM
  • User1692533347 posted

    Am i using the right way of if condition in XSLT?

    Friday, January 11, 2013 11:04 PM
  • User-1293249277 posted

    Put up a sample short xml , with different node names, but hierarcy of the xml element should be same. (You can put dummy values in the xml)

    Saturday, January 12, 2013 2:16 AM
  • User1692533347 posted

    This XSLT code is a template function that accept @ExpiryDate as parameter whcih is always blank. so if my "if conditions" are right then it should ago in at least 1 if condition. 

    I have updated the XSLT as well.

    Saturday, January 12, 2013 4:20 AM
  • User1546878023 posted

    You are probably facing issues with linespaces. Try writing

    <![CDATA[false]]>

    then you can use your string comparison.

    Otherwise you could also just write

    <xsl:variable name="showNews" select="ddwrt:FormatDateTime(@ExpiryDate, 1033, 'dd MMMM yyyy') =''/>

    And then you can write <xsl:if test="$showNews">

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, January 12, 2013 5:14 PM
  • User1692533347 posted

    thanx.

    Monday, January 14, 2013 6:12 AM