This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Conditional display of dates
- From: Wendell Piez <wapiez at mulberrytech dot com>
- To: xsl-list at lists dot mulberrytech dot com
- Date: Wed, 19 Dec 2001 15:12:11 -0500
- Subject: Re: [xsl] Conditional display of dates
- Reply-to: xsl-list at lists dot mulberrytech dot com
Hi Katie,
At 02:40 PM 12/19/01, you wrote:
>I am trying to display a date. I need to display the "Original Date" if
>it is returned.
Getting the value of the node will return the value if the node exists, but
nothing if it does not.
> If a Record with Name = ORIGINAL does not exist or the record with Name
> = ORIGINAL exists but a date for that record does not, I need to display
> the "Copy Date" (Name = COPY).
The second case subsumes the first (if the ORIGINAL record does not exist,
neither will it have a date), so we need to test only if there is (not) a date.
The template below does this, dropping the ORIGINAL date into a variable (a
node-set that either holds the date, or is empty) to make things a bit clearer.
<xsl:template match="RecordSet">
<xsl:variable name="originalDate"
select="Record/Name[.='ORIGINAL']/RecordHistorySet/RecordHistroy/Date"/>
<!-- bind the node to the variable -->
<!-- we want its value (which is nothing if it doesn't exist) -->
<xsl:value-of select="$originalDate"/>
<!-- if it does not exist, we get the other value -->
<xsl:if test="not($originalDate)">
<xsl:value-of
select="Record/Name[.='COPY']/RecordHistorySet/RecordHistroy/Date"/>
</xsl:if>
</xsl:template>
Does that help? A node-set tests as "true" if there is a node in the
node-set, "false" if not.
Cheers,
Wendell
======================================================================
Wendell Piez mailto:wapiez@mulberrytech.com
Mulberry Technologies, Inc. http://www.mulberrytech.com
17 West Jefferson Street Direct Phone: 301/315-9635
Suite 207 Phone: 301/315-9631
Rockville, MD 20850 Fax: 301/315-8285
----------------------------------------------------------------------
Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list