RE: [xsl] Insurance Transform (was XSL Tranformation!!)

Subject: RE: [xsl] Insurance Transform (was XSL Tranformation!!)
From: cknell@xxxxxxxxxx
Date: Wed, 29 Dec 2004 15:31:46 -0500
Here is a more compact, annotated version of the XSLT file. The first version may be clearer in that it is simpler. This version is smaller and may be easier to maintain.

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
  <xsl:output method="xml" indent="yes" encoding="UTF-8" />
  <xsl:strip-space elements="*" />

<!-- These three templates output nothing (the way we eliminate unwanted elements from the source document). -->
  <xsl:template match="Risk[not(@RepeatDet)]" />
  <xsl:template match="SeqNumber" />
  <xsl:template match="ExistingInsurancePaidBy" />
<!-- End -->

<!-- This template outputs the document element -->
  <xsl:template match="/">
    <fields>
      <xsl:apply-templates />
    </fields>
  </xsl:template>

<!-- This template matches the highest-level elements you want to process. -->
  <xsl:template match="Risk[@RepeatDet]">
    <xsl:apply-templates />
  </xsl:template>

<!-- This template matches all the elements higher up in the document structure than "Risk". -->
  <xsl:template match="doc|PFG|IDI|DiPolicy|Roles|Insured|Party">
    <xsl:apply-templates />
  </xsl:template>

<!-- This template matches all the source document elements that we want to turn into "field" elements in the output document. -->
<!-- Note the use of the "attribute value template (the curly braces). This is how you get the value of a variable into an attribute. -->
<!-- Note the use of variables. Each time the template is processed, the variable is re-created. That's how you get around the problem of variables being immutable. -->
  <xsl:template match="ExistingProductType|ExistingPolNumber|ExistingInsuranceAmt|ExistingInsuranceName|ExistingInsurancePending|ExistingInsuranceEP|ExistingInsuranceInd|ExistingInsuranceBP|ReplacementType">
    <xsl:variable name="sn" select="preceding-sibling::SeqNumber[1]" />
    <xsl:variable name="lname"><xsl:value-of select="local-name(.)" /></xsl:variable>
    <field name="{$lname}{$sn}"><value><xsl:value-of select="." /></value></field>
  </xsl:template>

</xsl:stylesheet>
-- 
Charles Knell
cknell@xxxxxxxxxx - email

Current Thread