[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

RE: [xsl] determine the number of payment methods and specify order depending on page type being viewed


Subject: RE: [xsl] determine the number of payment methods and specify order depending on page type being viewed
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Tue, 04 Nov 2008 13:10:42 -0500

At 10:57 AM 11/4/2008, Mike wrote:
How about a two-pass solution?

<xsl:template match="paymentMethods">
   <xsl:variable name="temp">
     <xsl:apply-templates select="directDebit"/>
     <xsl:apply-templates select="creditCard"/>
     <xsl:apply-templates select="invoice"/>
   </xsl:variable>
   <xsl:apply-templates select="$temp/*" mode="add-class"
</xsl:template>

<xsl:template match="directDebit">
  <directDebit>Payment by <br/>Direct Debit</directDebit>
</xsl:template>

<xsl:template match="creditCard">
  <creditCard>Payment by <br/>Credit Card</creditCard>
</xsl:template>

<xsl:template match="invoice">
  <invoice>Payment by <br/>Invoice</invoice>
</xsl:template>

<xsl:template match="*" mode="add-class">
  <xsl:variable name="status">
    <xsl:choose>
      <xsl:when test="$label = local-name()">current</xsl:when>
      <xsl:when test="preceding-sibling::*[local-name() =
$label]">completed</xsl:when>
      <xsl:otherwise/>
    </xsl:choose>
  </xsl:variable>
  <li class="doubleLine {$status}"><xsl:copy-of select="node()"/></li>
</xsl:template>

Probably doesn't save many lines of code, and it runs into the 1.0
node-set() restriction, but it strikes me as capturing the logic of the
problem a bit better: if a fourth and fifth kind of payment were added,
fewer changes would be needed, as the final template has no knowledge of the
different kinds of payment.

Indeed, and similarly the presentation in the result can be determined entirely by the order of the elements' selection by apply-templates, rather than having to be hard-wired into the logic (since assigning them a class of 'current' or 'completed' is relative to their position in the temporary tree, not bound by an implicit hierarchy of values of $label).


This is a good illustration of how being able to process results in XSLT 2.0 allows for better abstraction and therefore a better fit to the "real" rules, as opposed to the incidental rules, of the transformation. I think this distinction between "real" and "incidental" rules in specification is sometimes useful and important ... the real rules being the ones that support the underlying rationale, while the incidental rules only support the way the rationale expresses itself given particular extrinsic conditions, which also must obtain for them to be valid.

Cheers,
Wendell



======================================================================
Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
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
======================================================================


Current Thread
Keywords