Check if a string is null or empty in XSLT

前端 未结 14 1186
梦毁少年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 09:54

    test="categoryName != ''"
    

    Edit: This covers the most likely interpretation, in my opinion, of "[not] null or empty" as inferred from the question, including it's pseudo-code and my own early experience with XSLT. I.e., "What is the equivalent of the following Java?":

    !(categoryName == null || categoryName.equals(""))
    

    For more details e.g., distinctly identifying null vs. empty, see johnvey's answer below and/or the XSLT 'fiddle' I've adapted from that answer, which includes the option in Michael Kay's comment as well as the sixth possible interpretation.

提交回复
热议问题