[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

[xsl] Keys, IDs lookup tables.


Subject: [xsl] Keys, IDs lookup tables.
From: daniel whitney <dbf.whitney@xxxxxxxxx>
Date: Wed, 6 Jun 2012 10:41:14 -0400

Hi I'm having problems trying to figure out how to accomplish this and
what the best strategy might be.

It's a 2 part problem. The first with keys. The second with ID/IDREF.

1. I have an xml file with a "lookup" table at the top
(presentation/financiallegend). I want to output, as html, the
"longname" element in a table cell whether it exists in the "data" or
not. If it does exist in the data then the following  cells will
contain the financial data. If it doesn't exist, the following cells
would just be empty. My XSL file outputs the rows with financial data
correctly, but does not include rows where only the "longname" exists
(no financial data).

2. The header row of the table is a row of dates, each with a unique
id. The subequent rows are financial data that have to align with the
corresponding date id. The financial data include refs to their
corresponding date ids, but of course there might be ids without a
corresponding idref. So I have no idea how get the columns to align
correctly.

This is a very basic example. The file itself has dozens of lookup
tables (not too many IDs). So I'm wondering how to accomplisth this
and what is the best strategy to keep things as clean and simple as
possible.

Does having a schema contribute to the simplicity of the XSL somehow,
in regards to keys? Or are they essentially separate entities?

Any help is, of course, greatly appreciated.

Thanks,

Dan

XML file:

<?xml version="1.0" encoding="windows-1252"?>
<requesteddata>
<presentation>
<financiallegend>
<code>60.00</code>
<longname>Revenue - Operating/Total</longname>
</financiallegend>
<financiallegend>
<code>29.00</code>
<longname>Total Assets</longname>
</financiallegend>
<financiallegend>
<code>73.00</code>
<longname>Pre-Tax Income</longname>
</financiallegend>
<financiallegend>
<code>2.00</code>
<longname>Made-up filler</longname>
</financiallegend>
<financiallegend>
<code>82.00</code>
<longname>Net Income</longname>
</financiallegend>
</presentation>
<company>
<fpid>154</fpid>
<legal>High River Gold Mines Ltd.</legal>
<financials>
<perioddata>
<period id="154_2011-12-31_A_A_414785">
<perioddate>2011-12-31</perioddate>
<reporttype code="A">As reported</reporttype>
</period>
<period id="154_2010-12-31_A_R_414804">
<perioddate>2010-12-31</perioddate>
<reporttype code="R">Restated</reporttype>
</period>
<period id="154_2009-12-31_A_A_414700">
<perioddate>2010-12-31</perioddate>
<reporttype code="A">As reported</reporttype>
</period>
</perioddata>
<financialdata>
<financialgroup financiallegendcode="29.00" legend="Total Assets">
<financial periodref="154_2011-12-31_A_A_414785">1007827</financial>
<financial periodref="154_2010-12-31_A_R_414804">1102209</financial>
<financial periodref="154_2009-12-31_A_A_414700">209987</financial>
</financialgroup>
<financialgroup financiallegendcode="73.00" legend="Pre-Tax Income">
<financial periodref="154_2011-12-31_A_A_414785">231673</financial>
<financial periodref="154_2009-12-31_A_A_414700">191115</financial>
</financialgroup>
<financialgroup financiallegendcode="82.00" legend="Net Income">
<financial periodref="154_2010-12-31_A_R_414804">28999</financial>
<financial periodref="154_2009-12-31_A_A_414700">191203</financial>
</financialgroup>
<financialgroup financiallegendcode="60.00" legend="Revenue -
Operating/Total">
<financial periodref="154_2011-12-31_A_A_414785">573949</financial>
<financial periodref="154_2010-12-31_A_R_414804">529765</financial>
<financial periodref="154_2009-12-31_A_A_414700">447635</financial>
</financialgroup>
</financialdata>
</financials>
</company>
<company>
<fpid>11</fpid>
<legal>Barrick Gold</legal>
<financials>
<perioddata>
<period id="11_2011-12-31_A_A_1">
<perioddate>2011-12-31</perioddate>
<reporttype code="A">As reported</reporttype>
</period>
<period id="11_2010-12-31_A_A_2">
<perioddate>2010-12-31</perioddate>
<reporttype code="A">As reported</reporttype>
</period>
</perioddata>
<financialdata>
<financialgroup financiallegendcode="29.00" legend="Total Assets">
<financial periodref="11_2011-12-31_A_A_1">1007827</financial>
<financial periodref="11_2010-12-31_A_A_2">1102209</financial>
</financialgroup>
<financialgroup financiallegendcode="82.00" legend="Net Income">
<financial periodref="11_2010-12-31_A_A_2">191203</financial>
</financialgroup>
<financialgroup financiallegendcode="60.00" legend="Revenue -
Operating/Total">
<financial periodref="11_2011-12-31_A_A_1">573949</financial>
</financialgroup>
</financialdata>
</financials>
</company>
</requesteddata>


XSL file:

<?xml version="1.0" encoding="windows-1252"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0">
<xsl:output method="html" indent="yes" encoding="windows-1252"/>
<xsl:key name="legend" match="longname" use="../code"/>

<xsl:template match="requesteddata">
<xsl:for-each select="company">
<table border="1">
<tr>
<td colspan="4">
<xsl:value-of select="legal"/>
</td>
</tr>
<xsl:apply-templates select="financials/perioddata"/>
<xsl:apply-templates
select="financials/financialdata/financialgroup[key('legend',
@financiallegendcode)]"/>
</table>
</xsl:for-each>
</xsl:template>

<xsl:template match="perioddata">
<tr>
<td>&#160;</td>
<xsl:for-each select="period">
<td>
<xsl:value-of select="perioddate"/><xsl:text> -
</xsl:text><xsl:value-of select="reporttype"/>
</td>
</xsl:for-each>
</tr>
</xsl:template>

<xsl:template match="financials/financialdata/financialgroup">
<tr>
<td><xsl:value-of select="key('legend', @financiallegendcode)"/></td>
<xsl:for-each select="financial">
<td><xsl:value-of select="."/></td>
</xsl:for-each>
</tr>
</xsl:template>

<xsl:template name="presentation"/>
</xsl:stylesheet>

Output HTML example:

<table border="1">
<tr>
<td colspan="4">High River Gold Mines Ltd.</td>
</tr>
<tr>
<td>&#160;</td><td>2011-12-31 - As Reported</td><td>2010-12-31 -
Restated</td><td>2009-12-31 - As Reported</td>
</tr>
<tr>
<td>Revenue -
Operating/Total</td><td>573949</td><td>529765</td><td>447635</td>
</tr>
<tr>
<td>Total Assets</td><td>1007827</td><td>1102209</td><td>209987</td>
</tr>
<tr>
<td>Pre-Tax Income</td><td>231673</td><td>&#160;</td><td>191115</td>
</tr>
<tr>
<td>Made-up filler</td><td>&#160;</td><td>&#160;</td><td>&#160;</td>
</tr>
<tr>
<td>Net Income</td><td>&#160;</td><td>28999</td><td>191203</td>
</tr>
</table>

<table border="1">
<tr>
<td colspan="4">Barrick Gold</td>
</tr>
<tr>
<td>&#160;</td><td>2011-12-31 - As Reported</td><td>2010-12-31 - As
Reported</td>
</tr>
<tr>
<td>Revenue - Operating/Total</td><td>573949</td><td>&#160;</td>
</tr>
<tr>
<td>Total Assets</td><td>1007827</td><td>1102209</td>
</tr>
<tr>
<td>Pre-Tax Income</td><td>&#160;</td><td>&#160;</td>
</tr>
<tr>
<td>Made-up filler</td><td>&#160;</td><td>&#160;</td>
</tr>
<tr>
<td>Net Income</td><td>&#160;</td><td>191203</td>
</tr>
</table>


Current Thread
Keywords