[xsl] Determining if an optional attribute is present

Subject: [xsl] Determining if an optional attribute is present
From: "Sam Carleton" <scarleton@xxxxxxxxxxxxxxxx>
Date: Tue, 17 Oct 2006 12:36:35 -0400
Determining if an optional attribute is present

Here is the source XML:

<node id="1" version="1">
</node>
<node id="4" version="3" revision="2">
</node>

Here is the output I need:

<node id="1" version="1" revision="0">
</node>
<node id="4" version="3" revision="2">
</node>

Logically it would seem that this would do it:

<xsl:attribute name="revision">
 <xsl:if test="not(string(@revision)) = false()">
   <xsl:value-of select="@revision"/>
 </xsl:if>
 <xsl:if test="not(string(@revision))">
   <xsl:text>0</xsl:text>
 </xsl:if>
</xsl:attribute>

But in both cases, whether or not the revision is present,
not(string(@revision)) always returns false.  I have tried this with
both the debugger in XMLSpy and with MSXML 4.0.  The target parser is
MS .Net 2.0.

Sam
--
Miltonstreet Photography
http://www.miltonstreet.com

Current Thread