Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 2nd, 2007, 05:17 PM
Registered User
 
Join Date: Jul 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Formating arbitrary data into a table.

Hello I'm taking a xml with arbitrary data and trying to create a html table with it. The following is a sample of what a input xml would look like.

Code:
<?xml version="1.0" encoding="utf-8"?>
<query>
    <schema>
        <column name="bi_PUID" />
        <column name="si_CredentialID" />
        <column name="si_CredentialType" />
        <column name="vc_CredentialName" />
        <column name="ti_NeedsRepl" />
        <column name="si_HashBucket" />
        <column name="dt_ChangeDatetime" />
        <column name="dt_DeleteDatetime" />
    </schema>
    <record>
        <bi_PUID>844427077615872</bi_PUID>
        <si_CredentialID>1</si_CredentialID>
        <si_CredentialType>0</si_CredentialType>
        <vc_CredentialName>bob%[email protected]</vc_CredentialName>
        <ti_NeedsRepl>1</ti_NeedsRepl>
        <si_HashBucket>9216</si_HashBucket>
        <dt_ChangeDatetime>6/22/2007 11:32:22 PM</dt_ChangeDatetime>
        <dt_DeleteDatetime />
    </record>
    <record>
        <bi_PUID>844427077615873</bi_PUID>
        <si_CredentialID>1</si_CredentialID>
        <si_CredentialType>0</si_CredentialType>
        <vc_CredentialName>george%[email protected]</vc_CredentialName>
        <ti_NeedsRepl>1</ti_NeedsRepl>
        <si_HashBucket>9216</si_HashBucket>
        <dt_ChangeDatetime>6/22/2007 11:32:22 PM</dt_ChangeDatetime>
        <dt_DeleteDatetime />
    </record>
</query>
Now, the problem for me is to keep the name of the column and use that to get the values of the spcific records.

Code:
<?xml version="1.0" encoding="utf-8"?>

<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:template match="/">
    <h2>Users</h2>
    <table border="1">
      <xsl:for-each select="query/schema/column">
        <xsl:variable name="column" select="@name"/>

        <td>
          <th bgcolor="#9acd32">
            <xsl:value-of select="@name"/>
          </th>
          <xsl:for-each select="../../record">
            <tr>
              <xsl:value-of select ="$column/text()"/>
            </tr>
          </xsl:for-each>
        </td>
      </xsl:for-each>
    </table>
  </xsl:template>
 
</xsl:stylesheet>
As you can see the i'm trying to store the @name as a variable, but i think it's saving it as a node instead of a string. I want something like:

Code:
<td>
    <th>bi_puid</th>
    <tr>844427077615872<tr>
    <tr>844427077615873<tr>si_CredentialID
<td>
<td>
    <th>si_CredentialID</th>
    <tr>1<tr>
    <tr>1<tr>
<td>

...
 
Old July 2nd, 2007, 05:40 PM
Friend of Wrox
 
Join Date: Jul 2006
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
Send a message via Yahoo to bonekrusher
Default

Hi and welcome to the forum:

This should get you started:
Code:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
        <h2>Users</h2>
        <table border="1">
            <xsl:for-each select="query">
                <tr>
                    <xsl:for-each select="schema">
                        <xsl:for-each select="column">
                            <td>
                                <xsl:value-of select="@name"/>
                            </td>
                        </xsl:for-each>
                    </xsl:for-each>
                </tr>
                <tr>
                    <xsl:for-each select="record">
                        <td>
                            <xsl:value-of select="bi_PUID"/>
                        </td>
                        <td>
                            <xsl:value-of select="si_CredentialID"/>
                        </td>
                        <td>
                            <xsl:value-of select="si_CredentialType"/>
                        </td>
                    </xsl:for-each>
                </tr>
            </xsl:for-each>
        </table>
    </xsl:template>
</xsl:stylesheet>
First you need to loop through and create your header, then fill in the table cells.

Good luck







Similar Threads
Thread Thread Starter Forum Replies Last Post
Updating one table with data from another table dirtdog22 Access VBA 1 January 21st, 2008 04:41 PM
Formating the data Table values in XSLT vimalpatel2u XSLT 5 October 5th, 2007 04:41 AM
How to Update one table with other table data? ramk_1978 SQL Language 2 May 26th, 2006 12:51 AM
Print arbitrary text Joachim Hofmann SQL Language 0 November 14th, 2005 06:23 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.