1<?xml version="1.0" encoding="ISO-8859-1"?> 2<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> 3 4 <!-- FileName: variable69 --> 5 <!-- Document: http://www.w3.org/TR/xslt --> 6 <!-- DocVersion: 19991116 --> 7 <!-- Section: 11.6 --> 8 <!-- Creator: David Marston --> 9 <!-- Purpose: Demonstrate various tests of nullness on global variables --> 10 11<xsl:output method="xml" indent="no" encoding="UTF-8"/> 12 13<xsl:variable name="NotSet"/> 14<xsl:variable name="String" select="'string'"/> 15<xsl:variable name="nString" select="''"/> 16<xsl:variable name="Node" select="/doc/a"/> 17<xsl:variable name="nNode" select="/doc/b"/><!-- No element of that name in source. --> 18 19<xsl:template match="doc"> 20 <out> 21 <xsl:text>NotSet: </xsl:text> 22 <xsl:choose> 23 <xsl:when test="$NotSet = ''"><xsl:text>equals empty</xsl:text></xsl:when> 24 <xsl:when test="$NotSet != ''"><xsl:text>not empty</xsl:text></xsl:when> 25 <xsl:otherwise><xsl:text>neither</xsl:text></xsl:otherwise> 26 </xsl:choose> 27 <xsl:text> 28String: </xsl:text> 29 <xsl:choose> 30 <xsl:when test="$String = ''"><xsl:text>equals empty</xsl:text></xsl:when> 31 <xsl:when test="$String != ''"><xsl:text>not empty</xsl:text></xsl:when> 32 <xsl:otherwise><xsl:text>neither</xsl:text></xsl:otherwise> 33 </xsl:choose> 34 <xsl:text> 35nString: </xsl:text> 36 <xsl:choose> 37 <xsl:when test="$nString = ''"><xsl:text>equals empty</xsl:text></xsl:when> 38 <xsl:when test="$nString != ''"><xsl:text>not empty</xsl:text></xsl:when> 39 <xsl:otherwise><xsl:text>neither</xsl:text></xsl:otherwise> 40 </xsl:choose> 41 <xsl:text> 42Node: </xsl:text> 43 <xsl:choose> 44 <xsl:when test="$Node = ''"><xsl:text>equals empty</xsl:text></xsl:when> 45 <xsl:when test="$Node != ''"><xsl:text>not empty</xsl:text></xsl:when> 46 <xsl:otherwise><xsl:text>neither</xsl:text></xsl:otherwise> 47 </xsl:choose> 48 <xsl:text> 49nNode: </xsl:text> 50 <xsl:choose> 51 <xsl:when test="$nNode = ''"><xsl:text>equals empty</xsl:text></xsl:when> 52 <xsl:when test="$nNode != ''"><xsl:text>not empty</xsl:text></xsl:when> 53 <xsl:otherwise><xsl:text>neither</xsl:text></xsl:otherwise> 54 </xsl:choose> 55 </out> 56</xsl:template> 57 58 59 <!-- 60 * Licensed to the Apache Software Foundation (ASF) under one 61 * or more contributor license agreements. See the NOTICE file 62 * distributed with this work for additional information 63 * regarding copyright ownership. The ASF licenses this file 64 * to you under the Apache License, Version 2.0 (the "License"); 65 * you may not use this file except in compliance with the License. 66 * You may obtain a copy of the License at 67 * 68 * http://www.apache.org/licenses/LICENSE-2.0 69 * 70 * Unless required by applicable law or agreed to in writing, software 71 * distributed under the License is distributed on an "AS IS" BASIS, 72 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 73 * See the License for the specific language governing permissions and 74 * limitations under the License. 75 --> 76 77</xsl:stylesheet> 78