Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: absolut beginner request help with xslt Write!

From: "Joe Fawcett" <joefawcett@---------.------>
To: NULL
Date: 10/11/2007 8:38:00 AM

You haven't shown the structure of the XML but if the PAYMENTS is a child of 
the document element you're too high up the tree to access it by just using 
its name. You could change it to <xsl:for-each select="*/PAYMENTS">.
Personally I would use apply-templates not for-each, it makes the code so 
much easier to read and maintain. If this is the full XML:

<POLICY>
<HEADER>
some stuff here
</HEADER>
<PAYMENTS>
<INSTALLMENT_PAYMENT>
<POLICY_NUMBER>HMGW100289</POLICY_NUMBER>
<START_DATE>20070810</START_DATE>
<EXPIRY_DATE>20080810</EXPIRY_DATE>
<RISK_STATE>NSW</RISK_STATE>
<PAYMENT_DATE>20070712</PAYMENT_DATE>
<BRANCH_ID>1519322</BRANCH_ID>
<PREMIUM>-24.18</PREMIUM>
<FEES>
<FEE_DESCR>FSL</FEE_DESCR>
<TOTAL_FEE_AMOUNT>-2.86</TOTAL_FEE_AMOUNT>
</FEES>
<FEES>
<FEE_DESCR>GST</FEE_DESCR>
<TOTAL_FEE_AMOUNT>-2.02</TOTAL_FEE_AMOUNT>
</FEES>
<FEES>
<FEE_DESCR>SD</FEE_DESCR>
<TOTAL_FEE_AMOUNT>-2</TOTAL_FEE_AMOUNT>
</FEES>
<COMMISSION>-3.46</COMMISSION>
<AGENT_FEE>0</AGENT_FEE>
<AGENT_FEE_GST>0</AGENT_FEE_GST>
<CANCELLATION _FEE="">20</CANCELLATION>
</INSTALLMENT_PAYMENT>
</PAYMENTS>
</POLICY>

Then something like this, the tables don't seem right to me but I have 
followed your coding, shouldn't FEESW element be in a new row?
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<xsl:apply-templates select="POLICY" />
</body>
</html>
</xsl:template>
<xsl:template match="POLICY">
<table width="100%" border="1" bgcolor="LemonChiffon">
<tr bgcolor="#9acd32">
<th align="left">POLICY_NUMBER</th>
<th align="left">START_DATE</th>
<th align="left">EXPIRY_DATE</th>
<th align="left">RISK_STATE</th>
<th align="left">PAYMENT_DATE</th>
<th align="left">BRANCH_ID</th>
<th align="left">PREMIUM</th>
<th align="left">FLS</th>
<th align="left">GST</th>
<th align="left">SD</th>
<th align="left">COM</th>
<th align="left">AGENT_FEE</th>
<th align="left">AGENT_FEE_GST</th>
<th align="left">CANCELLATION_FEE</th>
</tr>
<xsl:apply-templates select="PAYMENTS" />
</table>
</xsl:template>
<xsl:template match="PAYMENTS">
<xsl:apply-templates select="INSTALLMENT_PAYMENT" />
</xsl:template>
<xsl:template match="INSTALLMENT_PAYMENT">
<tr>
<td>
<xsl:value-of select="POLICY_NUMBER"/>
</td>
<td>
<xsl:value-of select="START_DATE"/>
</td>
<td>
<xsl:value-of select="EXPIRY_DATE"/>
</td>
<td>
<xsl:value-of select="RISK_STATE"/>
</td>
<td>
<xsl:value-of select="PAYMENT_DATE"/>
</td>
<td>
<xsl:value-of select="BRANCH_ID"/>
</td>
<td>
<xsl:value-of select="PREMIUM"/>
</td>
<xsl:apply-templates select="FEES" />
</tr>
</xsl:template>
<xsl:template match="FEES">
<td>
<xsl:value-of select="TOTAL_FEE_AMOUNT"/>
</td>
<td>
<xsl:value-of select="TOTAL_FEE_AMOUNT"/>
</td>
<td>
<xsl:value-of select="TOTAL_FEE_AMOUNT"/>
</td>
</xsl:template>
</xsl:stylesheet>


-- 

Joe Fawcett (MVP - XML)
http://joe.fawcett.name

.googlegroups.com...
> Hi there
> I have an xml file, fo which I want to import the data to Access 2003.
> As I amnot getting the format that I am looking for, I want to use
> xslt to transform the data. The initial start got me to produce the
> header out put format but not the rest. I was wondering weather
> someone could hint me over the next hurdle? or point me to a site that
> has some tutorial. any hints are wellcome
>
> here is what I have got;
> <?xml version="1.0" encoding="utf-8"?>
>
> <xsl:stylesheet version="1.0"
>    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
>
> <xsl:template match="/">
>    <html>
>    <body>
>    <table width="100%" border="1" bgcolor="LemonChiffon">
>     <tr bgcolor="#9acd32">
>          <th align="left">POLICY_NUMBER</th>
>          <th align="left">START_DATE</th>
>          <th align="left">EXPIRY_DATE</th>
>          <th align="left">RISK_STATE</th>
>          <th align="left">PAYMENT_DATE</th>
>          <th align="left">BRANCH_ID</th>
>          <th align="left">PREMIUM</th>
>          <th align="left">FLS</th>
>          <th align="left">GST</th>
>          <th align="left">SD</th>
>          <th align="left">COM</th>
>          <th align="left">AGENT_FEE</th>
>          <th align="left">AGENT_FEE_GST</th>
>          <th align="left">CANCELLATION_FEE</th>
>        </tr>
>        <xsl:for-each select="PAYMENTS">
>         <xsl:for-each select="INSTALLMENT_PAYMENT">
>          <tr>
>            <td><xsl:value-of select="POLICY_NUMBER"/></td>
>            <td><xsl:value-of select="START_DATE"/></td>
>            <td><xsl:value-of select="EXPIRY_DATE"/></td>
>            <td><xsl:value-of select="RISK_STATE"/></td>
>            <td><xsl:value-of select="PAYMENT_DATE"/></td>
>            <td><xsl:value-of select="BRANCH_ID"/></td>
>            <td><xsl:value-of select="PREMIUM"/></td>
> <xsl:for-each select="FEES">
>            <td>
>               <xsl:value-of select="TOTAL_FEE_AMOUNT"/>
>             </td>
> <td>
>               <xsl:value-of select="TOTAL_FEE_AMOUNT"/>
>             </td>
> <td>
>               <xsl:value-of select="TOTAL_FEE_AMOUNT"/>
>             </td>
> </xsl:for-each>
>          </tr>
>         </xsl:for-each>
>       </xsl:for-each>
>      </table>
>    </body>
>  </html>
> </xsl:template>
> </xsl:stylesheet>
>
> and her is the detail section of the xml file:
> <HEADER>
>  some stuff here
> </HEADER>
> <PAYMENTS>
> <INSTALLMENT_PAYMENT>
> <POLICY_NUMBER>HMGW100289</POLICY_NUMBER>
> <START_DATE>20070810</START_DATE>
> <EXPIRY_DATE>20080810</EXPIRY_DATE>
> <RISK_STATE>NSW</RISK_STATE>
> <PAYMENT_DATE>20070712</PAYMENT_DATE>
> <BRANCH_ID>1519322</BRANCH_ID>
> <PREMIUM>-24.18</PREMIUM>
> <FEES>
> <FEE_DESCR>FSL</FEE_DESCR>
> <TOTAL_FEE_AMOUNT>-2.86</TOTAL_FEE_AMOUNT>
> </FEES>
> <FEES>
> <FEE_DESCR>GST</FEE_DESCR>
> <TOTAL_FEE_AMOUNT>-2.02</TOTAL_FEE_AMOUNT>
> </FEES>
> <FEES>
> <FEE_DESCR>SD</FEE_DESCR>
> <TOTAL_FEE_AMOUNT>-2</TOTAL_FEE_AMOUNT>
> </FEES>
> <COMMISSION>-3.46</COMMISSION>
> <AGENT_FEE>0</AGENT_FEE>
> <AGENT_FEE_GST>0</AGENT_FEE_GST>
> <CANCELLATION _FEE>20</CANCELLATION _FEE>
> </INSTALLMENT_PAYMENT>
> 




transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent