[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

[xsl] XSL, when elements don't exist


Subject: [xsl] XSL, when elements don't exist
From: Tanya S Buchanan <tanyana@xxxxxxxxxx>
Date: Tue, 28 Oct 2003 14:37:24 -0500




I'm trying to process an XML document for which certain elements may or may
not exist.
How can I handle this?
E.g.
<xsl:if test= "element exists">    <do something/>
</xsl:if>
<xsl:if test= "element does not exist">    <do something else/>
</xsl:if>

Partial XML document:
<PropertyGroup name="WorkItem"
class="com.ibm.xml.parsers.performance.workitems.Xerces2DOMCount">
<property name="d" displayname="Defer Node Expansion" value="true" />
<property name="f" displayname="Schema Full Support" value="false" />
<property name="gpn" displayname="Grammar Pool Name"
value="org.apache.xerces.util.XMLGrammarPoolImpl" />  <property name="grc"
displayname="Grammar Caching" value="true" />  <property name="l"
displayname="Load External DTD" value="true" />  <property name="m"
displayname="Memory Read" value="true" />  <property name="n"
displayname="Namespaces" value="true" />  <property name="s"
displayname="Schema Support" value="false" />  <property name="sid"
displayname="Set SystemID" value="true" />  <property name="tr"
displayname="Traverse DOM" value="true" />  <property name="uri"
displayname="URI" value="doc.xml" />  <property name="v"
displayname="Validation" value="true" />  </PropertyGroup>
These elements aren't always present, and when they are not I need to do
something
<property name="d" displayname="Defer Node Expansion" value="true" />
<property name="tr" displayname="Traverse DOM" value="true" />

Partial XSL document:
I have tried:
This gives me no output:
<xsl:when test="@displayname != string('Traverse DOM') and
string-length(normalize-space(@displayname)) = 0">
<xsl:text>n/a</xsl:text>   </xsl:when>

The ones below gives me output for each property /displayname, but I only
need it to print for one occasion:
<xsl:when test="@displayname != string('Traverse DOM') ">
<xsl:text>n/a</xsl:text> </xsl:when>

<xsl:when test="@displayname != string('Traverse DOM') and
string-length(normalize-space(property/@displayname)) = 0">
<xsl:text>n/a</xsl:text>
</xsl:when>

Any help you can provide would be appreciated.
Thanks, Tanya


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



Current Thread
Keywords