RE: [xsl] how do you determine if a property exists?

Subject: RE: [xsl] how do you determine if a property exists?
From: David Buddrige <dbuddrige@xxxxxxxxx>
Date: Thu, 15 Apr 2004 01:17:38 -0700 (PDT)
--- Jarno.Elovirta@xxxxxxxxx wrote:
> if you want to test if the attribute
> exists, then simply
> 
>   <xsl:when test="@Predecessors">
> 

For some reason, this doesn't seem to work for me.  I
am using saxon as my xslt processor.

I have the following data:

<?xml version="1.0" encoding="iso-8859-1"?>
<info>
	<mytag duration="3 days" />
	<mytag />
	<mytag duration="6 hours" />
	<mytag duration="33 hours" />
	<mytag duration="" />
	<mytag duration="13 hours" />
	<mytag duration="5 days" />
	<mytag duration="" />
	<mytag duration="3 hours" />
	<mytag duration="23 hours" />
</info>


Here is my template:

<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
	<xsl:template match="/">
		<myoutput>
			<xsl:apply-templates/>
		</myoutput>
	</xsl:template>
	<xsl:template match="mytag">
		<xsl:element name="myelement">
			<xsl:attribute name="time">
				<xsl:choose>
					<xsl:when test="@duration=''">1</xsl:when>
					<xsl:when test="@duration">1</xsl:when>
					<xsl:otherwise><xsl:value-of
select="@duration"/></xsl:otherwise>
				</xsl:choose>
			</xsl:attribute>
		</xsl:element>
	</xsl:template>
</xsl:stylesheet>


And here is the output that I get - note that the
second element has an empty attribute, where it
*should* take the value of 1, given that the second
element in the source data has no duration
attribute...

<?xml version="1.0" encoding="UTF-8"?><myoutput>
	<myelement time="1"/>
	<myelement time=""/>
	<myelement time="1"/>
	<myelement time="1"/>
	<myelement time="1"/>
	<myelement time="1"/>
	<myelement time="1"/>
	<myelement time="1"/>
	<myelement time="1"/>
	<myelement time="1"/>
</myoutput>

Does anyone know what might be wrong here?

thanks heaps guys

David Buddrige. 8-)


	
		
__________________________________
Do you Yahoo!?
Yahoo! Tax Center - File online by April 15th
http://taxes.yahoo.com/filing.html

Current Thread