[KLUG Members] Re: XSLT Transforms

Adam Williams members@kalamazoolinux.org
13 Jan 2003 20:37:28 -0500


--=-SLNgn1q/KImFa4zhsurI
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

>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"/>

Thanks, that was just the bit I needed.  This is great stuff.  With PHP
4.2.3's built in XML DOM object handling, and classes utilizing an ODBC
connection to views defined in a database the logic to generate the data
set is almost poetic.  Some of the most elegant code I've ever seen;
immense functionality in a small amount of code and yet still very easy
to follow and understand.  Then the XSLT turns the data into a viewable
HTML file.  The layers of process couldn't be more clearly defined, and
I can modify anyone of them without disturbing the layer above or
beneath it.  This rocks!

If I used the XSLT to produce SGML (which unfortunately I don't know), 
I would presumably then be able to produce HTML, Postscript, PDF,
etc...?

Anyone want to give a presentation on SGML?





--=-SLNgn1q/KImFa4zhsurI
Content-Disposition: attachment; filename=customer_price_matrix2html.xslt
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; name=customer_price_matrix2html.xslt; charset=ISO-8859-1

<?xml version=3D"1.0"?>
<!--=20
<customer_price_matrix_report>
  <salesperson name=3D"" mail=3D"" customercount=3D"0"/>
  <salesperson name=3D"" mail=3D"" customercount=3D"41">
    <customer name=3D"1ST AYD CORPORATION" company=3D"ME"
      number=3D"10225" city=3D"ELGIN" state=3D"IL"/>
     <customer name=3D"ASC INCORPORATED" company=3D"ME"
       number=3D"10421" city=3D"SOUTHGATE" state=3D"MI"/>
     <customer name=3D"CITY OF STURGIS" company=3D"ME"
       number=3D"10268" city=3D"STURGIS" state=3D"MI">
        <oem_discount oem=3D"" captive=3D"1.1" noncaptive=3D"1.0"
         user=3D"sswonk    " date=3D"2001-03-20 12:09"/>
       <oem_discount oem=3D"AAA" captive=3D"1.0" noncaptive=3D"1.0"
         user=3D"sswonk    " date=3D"2001-03-20 12:09"/>
      </customer>
-->
<xsl:stylesheet version=3D"1.0" xmlns:xsl=3D"http://www.w3.org/1999/XSL/Tra=
nsform">


  <xsl:output method=3D"html"/>

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

  <xsl:template match=3D"salesperson[customer]">
	<h2><xsl:value-of select=3D"@name"/></h2>
    <table>
	  <tr>
	    <th align=3D"center" valign=3D"bottom">Customer<br/>name</th>
	    <th align=3D"center" valign=3D"bottom">Company<br/>Code</th>
	    <th align=3D"center" valign=3D"bottom">Customer's<br/>City</th>
	    <th align=3D"center" valign=3D"bottom">Customer's<br/>State</th>
      </tr>  =20
	  <xsl:apply-templates/>
	</table>
  </xsl:template>

  <xsl:template match=3D"salesperson">
	<h2><xsl:value-of select=3D"@name"/></h2>
    <table>
	  <tr>
	    <td colspan=3D"4">Salesperson has no customers assigned</td>
      </tr>  =20
	  <xsl:apply-templates/>
	</table>
  </xsl:template>


    <xsl:template match=3D"customer[oem_discount]">
	<tr>
        <td><xsl:value-of select=3D"@name"/></td>
        <td><xsl:value-of select=3D"@company"/></td>
        <td><xsl:value-of select=3D"@city"/></td>
        <td><xsl:value-of select=3D"@state"/></td>
	</tr>
	<tr>
	    <td align=3D"left" colspan=3D"4"><u>Customer OEM Discounts</u></td>
	</tr>
	<tr>
	    <td align=3D"center" colspan=3D"4">
	      <table cellpadding=3D"3" cellspacing=3D"3">
	        <tr>
	           <th align=3D"center" valign=3D"bottom">OEM</th>
	           <th align=3D"center" valign=3D"bottom">Captive<br/>Discount</th=
>
	           <th align=3D"center" valign=3D"bottom">Non-Captive<br/>Discount=
</th>
	           <th align=3D"center" valign=3D"bottom">User<br/>Id</th>
	           <th align=3D"center" valign=3D"bottom">Update<br/>Date</th>
	        </tr>
  	      <xsl:apply-templates/>
  	    </table>
  	  </td>
    </tr>
    </xsl:template>
   =20
   =20
    <xsl:template match=3D"customer">
	  <tr>
        <td><xsl:value-of select=3D"@name"/></td>
        <td><xsl:value-of select=3D"@company"/></td>
        <td><xsl:value-of select=3D"@city"/></td>
        <td><xsl:value-of select=3D"@state"/></td>
	  </tr>
    </xsl:template>   =20

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

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

</xsl:stylesheet>

--=-SLNgn1q/KImFa4zhsurI--