Check if a string is null or empty in XSLT

前端 未结 14 1225
梦毁少年i
梦毁少年i 2020-11-27 09:12

How can I check if a value is null or empty with XSL?

For example, if categoryName is empty? I\'m using a when choosing construct.

For

14条回答
  •  我在风中等你
    2020-11-27 10:04

    In some cases, you might want to know when the value is specifically null, which is particularly necessary when using XML which has been serialized from .NET objects. While the accepted answer works for this, it also returns the same result when the string is blank or empty, i.e. '', so you can't differentiate.

    
        
            item 1
            
        
    
    

    So you can simply test the attribute.

    
       Hello World.
    
    

    Sometimes it's necessary to know the exact state and you can't simply check if CategoryName is instantiated, because unlike say Javascript

    
       Hello World.
    
    

    Will return true for a null element.

提交回复
热议问题