[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Need better ways to do this..

Subject: Re: Need better ways to do this..
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Fri, 1 Jun 2001 11:17:47 +0100
xsl matching td elements
Hi Sudhir,

> 1. How to prevent the output being generated for td[4], td[5], td[6] and
> td[7] if td[1] fails my validation as shown in the XSL segment?

At the moment, all your templates are matching the td elements in your
source, which makes it hard to control which tr elements are processed
and which aren't.

Instead, you should have a template matching the tr element and
choosing whether or not the td elements inside it should be processed:

<xsl:template match="tr">
   <xsl:variable name="currentDate" select="td[1]"/>
   <xsl:variable name="isValid"
      select="datelogicext:checkValidity($StartDateObject,
                                         string( $currentDate ))" />
   <xsl:if test="$isValid = 'YES'">
      <!-- If valid, print the timestamp within XData tag -->
      <XData><xsl:value-of select="$currentDate"/></XData>
      <!-- Then go for other values in tr/td[4], tr/td[5], tr/td[6]
           and tr/td[7] -->
      <xsl:apply-templates select="td[4] | td[5] | td[6] | td[7]" />
   </xsl:if>
   <!-- otherwise nothing is output for this row -->
</xsl:template>

> 2. How to avoid repitition of the XSL code for processing td[4],
> td[5], td[6] and td[7]?

You can merge the templates into one using the | to separate the
individual patterns in the match attribute:

<xsl:template match="tr/td[4] | tr/td[5] | tr/td[6] | tr/td[7]">
   <YData>
      <xsl:choose>
         <xsl:when test=". = 'NA'">-9999</xsl:when>
         <xsl:otherwise><xsl:value-of select="." /></xsl:otherwise>
      </xsl:choose>
   </YData>
</xsl:template>

In fact, using the template that I gave for the tr element above means
that the *only* td elements that get templates applied to them are the
fourth, fifth, sixth and seventh within the row.  So you could
simplify the match pattern to:

<xsl:template match="td">
   <YData>
      <xsl:choose>
         <xsl:when test=". = 'NA'">-9999</xsl:when>
         <xsl:otherwise><xsl:value-of select="." /></xsl:otherwise>
      </xsl:choose>
   </YData>
</xsl:template>

I hope that helps,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/



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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.