XSL Question Please Help Sorry I'm still learning

XSL Question Please Help Sorry I'm still learning

Post by atbg » Sat, 05 Jul 2003 01:10:20



I would hope anyone can help me understand a certain problem I am currently
having with a small piece of code. I would be very grateful if anyone could
give me some ideas on how I could structure my XSL template to produce an
output similar to the following table given the attached Test.xml source. I
seem to be using for-each and the priority attribute but cant pinpoint where
to place it correctly.

View the Test.xml source at :
http://www.angelfire.com/pro/atbgmxsl/Test.xml

Required result in table format is :
ASXCode Company Name Company Statistics/Interim Dates Annual Balance
Sheet/Cash

RWS Rothbury Wines Limited -- 99,000

OCO Oriel Communications Limited 12/2002 97,065

NRL Newland Resources Limited 12/2002 95,143

MCL M2M Corporation Limited 12/2002 95,033

SUP Supersorb Environment NL 12/2002 94,328

 
 
 

XSL Question Please Help Sorry I'm still learning

Post by Marro » Sat, 05 Jul 2003 19:25:56


Hi,

It is difficult to give you any more than some pointers - because you have
text in the output which may or may not be coming from the input XML, e.g.
in the output where does the "Company Statistics/Interim Dates" text come
from (if it is supposed to be generated from the input XML you will have to
describe how it is derived).

Also, your XML looks a little odd - it is well-formed OK but just
structurally it looks a little strange because there are less <Column>
elements in the <Metadata> than there are <Column> elements in the <Record>
data?  The metadata descriptions also seem to be out of sync with the record
columns.

Anyway, in the simplest form to get an output you might have...

== XSL1 ====================================
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.veryComputer.com/;>
<xsl:output method="html" indent="yes"/>
<xsl:template match="/">
  <html>
    <body>
      <table border="1">
        <tr>
          <th>ASXCode</th>
          <th>Company Name</th>
          <th>Company Statistics/Interim Dates</th>
          <th>Annual Balance Sheet/Cash</th>
        </tr>
        <xsl:for-each select="root/ResultSet/Record">
          <tr>
            <td>
              <xsl:value-of select="Column[1]"/>
            </td>
            <td>
              <xsl:value-of select="Column[2]"/>
            </td>
            <td>
              <xsl:value-of select="Column[5]"/>
            </td>
            <td>
              <xsl:value-of select="Column[7]"/>
            </td>
          </tr>
        </xsl:for-each>
      </table>
    </body>
  </html>
</xsl:template>
</xsl:stylesheet>
== end of XSL1 =============================

But I'm pretty sure that's not what you want - and isn't particularly
elegant XSLT code.  So if you wanted to use the metadata to produce column
headers for the table you might have something like...

== XSL2 ====================================
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.veryComputer.com/;>
<xsl:output method="html" indent="yes"/>
<xsl:template match="/">
  <html>
    <body>
      <xsl:apply-templates select="root/ResultSet"/>
    </body>
  </html>
</xsl:template>

<xsl:template match="ResultSet">
  <table border="1">
    <xsl:apply-templates select="Metadata"/>
    <xsl:apply-templates select="Record"/>
  </table>
</xsl:template>

<xsl:template match="Metadata">
  <tr>
    <xsl:for-each select="Column">
      <th>

      </th>
    </xsl:for-each>
  </tr>
</xsl:template>

<xsl:template match="Record">
  <tr>
    <xsl:for-each select="Column">
      <td>
        <xsl:value-of select="."/>
      </td>
    </xsl:for-each>
  </tr>
</xsl:template>
</xsl:stylesheet>
== end of XSL2 =============================

But with that you will see the problem with the metadata not matching the
record columns.

If you don't want to show all the columns you will have to define how and
why each column should or should not be displayed.

Hope this helps
Marrow
http://www.veryComputer.com/ - home of Xselerator (XSLT IDE and de*)
http://www.veryComputer.com/


Quote:> I would hope anyone can help me understand a certain problem I am
currently
> having with a small piece of code. I would be very grateful if anyone
could
> give me some ideas on how I could structure my XSL template to produce an
> output similar to the following table given the attached Test.xml source.
I
> seem to be using for-each and the priority attribute but cant pinpoint
where
> to place it correctly.

> View the Test.xml source at :
> http://www.veryComputer.com/

> Required result in table format is :
> ASXCode Company Name Company Statistics/Interim Dates Annual Balance
> Sheet/Cash

> RWS Rothbury Wines Limited -- 99,000

> OCO Oriel Communications Limited 12/2002 97,065

> NRL Newland Resources Limited 12/2002 95,143

> MCL M2M Corporation Limited 12/2002 95,033

> SUP Supersorb Environment NL 12/2002 94,328


 
 
 

1. XSL Question Please Help Sorry I'm still learning

I would hope anyone can help me understand a certain problem I am
currently having with a small piece of code. I would be very grateful if
anyone could give me some ideas on how I could structure my XSL template
to produce an output similar to the following table given the attached
Test.xml source. I seem to be using for-each and the priority attribute
but cant pinpoint where to place it correctly.

View the Test.xml source at :
http://www.angelfire.com/pro/atbgmxsl/Test.xml

Required result in table format is :
ASXCode Company Name Company Statistics/Interim Dates Annual Balance
Sheet/Cash

RWS Rothbury Wines Limited -- 99,000

OCO Oriel Communications Limited 12/2002 97,065

NRL Newland Resources Limited 12/2002 95,143

MCL M2M Corporation Limited 12/2002 95,033

SUP Supersorb Environment NL 12/2002 94,328

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

2. Tandy Tape Backup....

3. Please Help to create this xml file - Please help me to solve this problem Please

4. Compliant software turns out to be non-compliant - how often?

5. Simple question but i can't get it to work, please help

6. OSS: Arrow keys and VI

7. 1 to many problem ' XSLT ' --- please help me

8. FFIND command

9. "XML in a nutshell" or "Learning XML" - help please

10. Error with encoding='ISO-8859-1', please help.

11. XMLDSO misbehaving - please help - I'm sure it's simple

12. Beginner's book samples don't work, please help

13. UTF-8, XML, XSL, ASP help :) please - HELP HELP HELP