This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Need better ways to do this..


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]