[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Keys, IDs lookup tables.

Subject: Re: Keys, IDs lookup tables.
From: daniel whitney <dbf.whitney@xxxxxxxxx>
Date: Wed, 6 Jun 2012 15:31:05 -0400
 Re: Keys
OK so I came up with a solution for Part 2 of my question. Not sure if
it's the ideal, but it works:

Would Part 1 have a similar solution? Would I store the "lookup"
portion in a global variable and just call that again and again?


<xsl:template match="financialgroup">
<xsl:variable name="currentFinancial" select="financial"/>
<tr>
<td><xsl:value-of select="key('legend', @financiallegendcode)"/></td>
<xsl:for-each select="ancestor::financials/perioddata/period">
<xsl:variable name="idBase" select="@id"/>
<td align="right">
<xsl:choose>
<xsl:when test="$currentFinancial/@periodref=$idBase">
<xsl:value-of select="$currentFinancial[@periodref=$idBase]"/>
</xsl:when>
<xsl:otherwise>
<xsl:text>....</xsl:text>
</xsl:otherwise>
</xsl:choose>
</td>
</xsl:for-each>
</tr>
</xsl:template>


On Wed, Jun 6, 2012 at 10:41 AM, daniel whitney <dbf.whitney@xxxxxxxxx>
wrote:
> 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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.