xsl-list
[Top] [All Lists]

RE: Insurance Transform (was XSL Tranformation!!)

2004-12-29 13:31:46
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[(_at_)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(_at_)onebox(_dot_)com - email



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>