Subject:XSL Transformation help needed (original and new provided) Author:Anatoli Titarev Date:22 Apr 2005 01:45 AM Originally Posted: 22 Apr 2005 01:34 AM
Hi all,
I am to this forum and new to XSL. I am working on a generic reporting solution. XSL is the stumbling block.
I need to create an XSL stylesheet that converts ANY(!) XML created by .Net DataSet object into an XML file,
which can be diplayed in a web page using another stylesheet.
The DataSet can have results from multiple (!) queries.
The very first one unnamed SQL creates <table> node with the column names as children where text has the data.
Every new SQL creates Table1, Table2, etc. I need to convert all queries into headers with column names and rows with data.
Original:
<?xml version="1.0" standalone="yes"?>
<OriginalDataSet>
<Table>
<Column1>25.7500</Column1>
</Table>
<Table1>
<Test_x0020_Decimal>45.15</Test_x0020_Decimal>
</Table1>
<Table2>
<Today>2005-04-13T23:02:38.6270000+10:00</Today>
</Table2>
<Table3>
<Num_x0020_of_x0020_Authors>23</Num_x0020_of_x0020_Authors>
</Table3>
<Table4>
<Num_x0020_of_x0020_Employees>43</Num_x0020_of_x0020_Employees>
</Table4>
<Table5>
<Column1>Testing Output</Column1>
</Table5>
<Table6>
<au_id>172-32-1176</au_id>
<au_lname>White</au_lname>
<au_fname>Johnson</au_fname>
<phone>408 496-7223</phone>
<address>10932 Bigge Rd.</address>
<city>Menlo Park</city>
<state>CA</state>
<zip>94025</zip>
<contract>true</contract>
</Table6>
<Table6>
<au_id>213-46-8915</au_id>
<au_lname>Green</au_lname>
<au_fname>Marjorie</au_fname>
<phone>415 986-7020</phone>
<address>309 63rd St. #411</address>
<city>Oakland</city>
<state>CA</state>
<zip>94618</zip>
<contract>true</contract>
</Table6>
</OriginalDataSet>
New, comments are not necessary, they are for readability only
<?xml version="1.0" standalone="yes"?>
<?xml-stylesheet type="text/xsl" href="datasetstylesheet.xsl" ?>
<DATASET>
<!-- <Table> -->
<header>
<field>Column1</field>
</header>
<row>
<field>25.7500</field>
</row>
<!-- <Table1> -->
<header>
<field>Test_x0020_Decimal</field>
</header>
<row>
<field>45.15</field>
</row>
<!-- <Table2> -->
<header>
<field>Today</field>
</header>
<row>
<field>2005-04-13T23:02:38.6270000+10:00</field>
</row>
<!-- <Table3> -->
<header>
<field>Num_x0020_of_x0020_Authors</field>
</header>
<row>
<field>23</field>
</row>
<!-- <Table4> -->
<header>
<field>Num_x0020_of_x0020_Employees</field>
</header>
<row>
<field>43</field>
</row>
<!-- <Table5> -->
<header>
<field>Column1</field>
</header>
<row>
<field>Testing Output</field>
</row>
<!-- <Table6>, NOTE: only one header but 2 rows! -->
<header>
<field>au_id</field>
<field>au_lname</field>
<field>au_fname</field>
<field>phone</field>
<field>address</field>
<field>city</field>
<field>state</field>
<field>zip</field>
<field>contract</field>
</header>
<row>
<field>172-32-1176</field>
<field>White</field>
<field>Johnson</field>
<field>408 496-7223</field>
<field>10932 Bigge Rd.</field>
<field>Menlo Park</field>
<field>CA</field>
<field>94025</field>
<field>true</field>
</row>
<row>
<field>213-46-8915</field>
<field>Green</field>
<field>Marjorie</field>
<field>415 986-7020</field>
<field>309 63rd St. #411</field>
<field>Oakland</field>
<field>CA</field>
<field>94618</field>
<field>false</field>
</row>
</DATASET>
Your help is appreciated!
Anatoli If you need more info, please post here.
Subject:XSL Transformation help needed (original and new provided) Author:(Deleted User) Date:22 Apr 2005 04:09 AM
Hi Anatoli,
here is my solution; when the stylesheet matches the TableXX element, it checks if the preceding node had the same name: if it doesn't, it outputs the header. In any case it outputs a <row> element by iterating over the child elements.
Subject:XSL Transformation help needed (original and new provided) Author:(Deleted User) Date:25 Apr 2005 04:47 AM
Hi Anatoli,
the XSL I pasted in my previous message does generate only one <header> element for Table6. However, it fails to print the header for the first table.
This is the updated XSL