[KLUG Members] Re: XSLT Transforms

John Holland members@kalamazoolinux.org
Fri, 10 Jan 2003 18:04:44 -0500


--ZPt4rx8FFjLCG7dd
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

A XSL tranform file that does this is attached.  The important bit is to
have two customer templates; one matches customer elements having
oem_discount elements, the other catches the rest.  The first template
includes the header html and should match for oem_discount.

<xsl:template match="customer[oem_discount]">
	<xsl:apply-templates select="oem_discount"/>


<xsl:template match="customer">


On Thu, Jan 09, 2003 at 02:01:27PM -0500, Adam Williams wrote:
> I've looked about for a way to only include the header for customer
> discount entries if there are any (essentially an "if").  I've found
> code for doing counts, etc... but no obvious examples of how to properly
> create nested tables.

--------------------------------------------------------------------
John Holland 
john@zoner.org
http://www.zoner.org

--ZPt4rx8FFjLCG7dd
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="adam2.xsl"

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">


  <xsl:output method="html"/>

  <xsl:template match="/customer_price_matrix_report">
        <html>
        <head>
        </head>
        <body>
        <xsl:apply-templates/>
        </body>
        </html>
  </xsl:template>

  <xsl:template match="salesperson">
        <h2>Saleperson <xsl:value-of select="@name"/></h2>
    <table border="1">
          <tr>
            <th align="center" valign="bottom">Customer<br/>name</th>
            <th align="center" valign="bottom">Company<br/>Code</th>
            <th align="center" valign="bottom">Customer's<br/>City</th>
            <th align="center" valign="bottom">Customer's<br/>State</th>
      </tr>
          <xsl:apply-templates/>
        </table>
  </xsl:template>
  
    <xsl:template match="customer[oem_discount]">
        <tr>
        <td><xsl:value-of select="@name"/></td>
        <td><xsl:value-of select="@company"/></td>
        <td><xsl:value-of select="@city"/></td>
        <td><xsl:value-of select="@state"/></td>
        </tr>
        <tr>
            <td align="center" colspan="4">Customer OEM Discounts</td>
        </tr>
        <tr>
            <td align="center" colspan="4">
              <table>
                <tr>
                   <th align="center" valign="bottom">OEM</th>
                   <th align="center" valign="bottom">Captive<br/>Discount</th>
                   <th align="center" valign="bottom">Non-Captive<br/>Discount</th>
                   <th align="center" valign="bottom">User<br/>Id</th>
                   <th align="center" valign="bottom">Update<br/>Date</th>
                </tr>
              <xsl:apply-templates select="oem_discount"/>
            </table>
          </td>
    </tr>
    </xsl:template>

    <xsl:template match="customer">
        <tr>
        <td><xsl:value-of select="@name"/></td>
        <td><xsl:value-of select="@company"/></td>
        <td><xsl:value-of select="@city"/></td>
        <td><xsl:value-of select="@state"/></td>
        </tr>
    </xsl:template>

    <xsl:template match="oem_discount">
       <tr>
         <td><xsl:value-of select="@oem"/></td>
         <td><xsl:value-of select="@captive"/></td>
         <td><xsl:value-of select="@noncaptive"/></td>
         <td><xsl:value-of select="@user"/></td>
         <td><xsl:value-of select="@date"/></td>
       </tr>
    </xsl:template>

   <xsl:template match="text()|@*"/>

</xsl:stylesheet>


--ZPt4rx8FFjLCG7dd--