SusanLIMS
asked on
Using XSLT 1.0 to convert XML to HTML Table
I want to convert an XML file to an HTML table using XSLT. This is happening inside another application, and only XSL version 1.0 is supported. I'm new at using XSLT, so any help would be much appreciated!
Following are the original XML and the desired HTML output. Note that the output is a "flat" table, where the XML input has levels. I've also attached these as files if that is helpful.
Thanks much!
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<LabRequest>
<PATIENT>
<X_EXTERNAL_ID>9649ABC113< /X_EXTERNA L_ID>
<FIRST_NAME>Nancy</FIRST_N AME>
<LAST_NAME>Smithson</LAST_ NAME>
</PATIENT>
<CUSTOMER>
<NAME>JUNK_ALFALFA</NAME>
<X_CITY>Oklahoma City</X_CITY>
<X_STATE>OK</X_STATE>
<X_ZIPCODE>11557</X_ZIPCOD E>
</CUSTOMER>
<SAMPLE>
<X_TUBE_ID>Tube001</X_TUBE _ID>
<SAMPLED_DATE>2014-03-20T0 9:05:00.00 0-05:00</S AMPLED_DAT E>
<X_SPECIMEN_SOURCE>BLOOD</ X_SPECIMEN _SOURCE>
<ANALYSIS>
<X_LOINC>34487-9</X_LOINC>
</ANALYSIS>
<ANALYSIS>
<X_LOINC>12345-1</X_LOINC>
</ANALYSIS>
</SAMPLE>
<SAMPLE>
<X_TUBE_ID>Tube002</X_TUBE _ID>
<SAMPLED_DATE>2014-05-25T0 5:33:00.00 0-05:00</S AMPLED_DAT E>
<X_SPECIMEN_SOURCE>SERUM</ X_SPECIMEN _SOURCE>
<ANALYSIS>
<X_LOINC>55888-1</X_LOINC>
</ANALYSIS>
</SAMPLE>
</LabRequest>
Desired HTML:
<table>
<tr>
<th>Table</th>
<th>Field</th>
<th>Value</th>
</tr>
<tr>
<td>PATIENT</td>
<td>X_EXTERNAL_ID</td>
<td>9649ABC113</td>
</tr>
<tr>
<td>PATIENT</td>
<td>FIRST_NAME</td>
<td>Nancy</td>
</tr>
<tr>
<td>PATIENT</td>
<td>LAST_NAME</td>
<td>Smithson</td>
</tr>
<tr>
<td>CUSTOMER</td>
<td>NAME</td>
<td>JUNK_ALFALFA</td>
</tr>
<tr>
<td>CUSTOMER</td>
<td>X_CITY</td>
<td>Oklahoma City</td>
</tr>
<tr>
<td>CUSTOMER</td>
<td>X_STATE</td>
<td>OK</td>
</tr>
<tr>
<td>CUSTOMER</td>
<td>X_ZIPCODE</td>
<td>11557</td>
</tr>
<tr>
<td>SAMPLE</td>
<td>X_TUBE_ID</td>
<td>Tube001</td>
</tr>
<tr>
<td>SAMPLE</td>
<td>SAMPLED_DATE</td>
<td>03/20/2014 09:05:00 AM</td>
</tr>
<tr>
<td>SAMPLE</td>
<td>X_SPECIMEN_SOURCE</td>
<td>BLOOD</td>
</tr>
<tr>
<td>ANALYSIS</td>
<td>X_LOINC</td>
<td>34487-9</td>
</tr>
<tr>
<td>ANALYSIS</td>
<td>X_LOINC</td>
<td>12345-1</td>
</tr>
<tr>
<td>SAMPLE</td>
<td>X_TUBE_ID</td>
<td>Tube002</td>
</tr>
<tr>
<td>SAMPLE</td>
<td>SAMPLED_DATE</td>
<td>05/25/2014 05:33:00 AM</td>
</tr>
<tr>
<td>SAMPLE</td>
<td>X_SPECIMEN_SOURCE</td>
<td>SERUM</td>
</tr>
<tr>
<td>ANALYSIS</td>
<td>X_LOINC</td>
<td>55888-1</td>
</tr>
</table>
ExampleShort2.xml
ExampleShort2.html
Following are the original XML and the desired HTML output. Note that the output is a "flat" table, where the XML input has levels. I've also attached these as files if that is helpful.
Thanks much!
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<LabRequest>
<PATIENT>
<X_EXTERNAL_ID>9649ABC113<
<FIRST_NAME>Nancy</FIRST_N
<LAST_NAME>Smithson</LAST_
</PATIENT>
<CUSTOMER>
<NAME>JUNK_ALFALFA</NAME>
<X_CITY>Oklahoma City</X_CITY>
<X_STATE>OK</X_STATE>
<X_ZIPCODE>11557</X_ZIPCOD
</CUSTOMER>
<SAMPLE>
<X_TUBE_ID>Tube001</X_TUBE
<SAMPLED_DATE>2014-03-20T0
<X_SPECIMEN_SOURCE>BLOOD</
<ANALYSIS>
<X_LOINC>34487-9</X_LOINC>
</ANALYSIS>
<ANALYSIS>
<X_LOINC>12345-1</X_LOINC>
</ANALYSIS>
</SAMPLE>
<SAMPLE>
<X_TUBE_ID>Tube002</X_TUBE
<SAMPLED_DATE>2014-05-25T0
<X_SPECIMEN_SOURCE>SERUM</
<ANALYSIS>
<X_LOINC>55888-1</X_LOINC>
</ANALYSIS>
</SAMPLE>
</LabRequest>
Desired HTML:
<table>
<tr>
<th>Table</th>
<th>Field</th>
<th>Value</th>
</tr>
<tr>
<td>PATIENT</td>
<td>X_EXTERNAL_ID</td>
<td>9649ABC113</td>
</tr>
<tr>
<td>PATIENT</td>
<td>FIRST_NAME</td>
<td>Nancy</td>
</tr>
<tr>
<td>PATIENT</td>
<td>LAST_NAME</td>
<td>Smithson</td>
</tr>
<tr>
<td>CUSTOMER</td>
<td>NAME</td>
<td>JUNK_ALFALFA</td>
</tr>
<tr>
<td>CUSTOMER</td>
<td>X_CITY</td>
<td>Oklahoma City</td>
</tr>
<tr>
<td>CUSTOMER</td>
<td>X_STATE</td>
<td>OK</td>
</tr>
<tr>
<td>CUSTOMER</td>
<td>X_ZIPCODE</td>
<td>11557</td>
</tr>
<tr>
<td>SAMPLE</td>
<td>X_TUBE_ID</td>
<td>Tube001</td>
</tr>
<tr>
<td>SAMPLE</td>
<td>SAMPLED_DATE</td>
<td>03/20/2014 09:05:00 AM</td>
</tr>
<tr>
<td>SAMPLE</td>
<td>X_SPECIMEN_SOURCE</td>
<td>BLOOD</td>
</tr>
<tr>
<td>ANALYSIS</td>
<td>X_LOINC</td>
<td>34487-9</td>
</tr>
<tr>
<td>ANALYSIS</td>
<td>X_LOINC</td>
<td>12345-1</td>
</tr>
<tr>
<td>SAMPLE</td>
<td>X_TUBE_ID</td>
<td>Tube002</td>
</tr>
<tr>
<td>SAMPLE</td>
<td>SAMPLED_DATE</td>
<td>05/25/2014 05:33:00 AM</td>
</tr>
<tr>
<td>SAMPLE</td>
<td>X_SPECIMEN_SOURCE</td>
<td>SERUM</td>
</tr>
<tr>
<td>ANALYSIS</td>
<td>X_LOINC</td>
<td>55888-1</td>
</tr>
</table>
ExampleShort2.xml
ExampleShort2.html
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
This is awesome..thank you so much. I got the first two examples to work, but I get an error on the 3rd. I like the idea of a separating line between the samples - any idea what the error might be?
I tried the following two online tools - and both threw an error on the 3rd example that contains the following line:
<TR><TD colspan=3">--------------- ---------- ---------- ---------- --------</ TD></TR>
http://www.freeformatter.com/xsl-transformer.html#ad-output
http://xslt.online-toolz.com/tools/xslt-transformation.php
Really appreciate the help...thanks...
I tried the following two online tools - and both threw an error on the 3rd example that contains the following line:
<TR><TD colspan=3">---------------
http://www.freeformatter.com/xsl-transformer.html#ad-output
http://xslt.online-toolz.com/tools/xslt-transformation.php
Really appreciate the help...thanks...
Oh, well, the third example was not tested,
apparently I missed a quote for the attribute
apparently I missed a quote for the attribute
<TR><TD colspan="3">-----------------------------------------------------</TD></TR>
ASKER
Fantastic...THANKS to both of you!!
welcome
I know the result is as you wanted it, but you could add an empty row at the start of each SAMPLE
in order to visualy seperate them, how else is the consumer of this table going to figure out to which sample a certain aspect belongs
Open in new window
just a thought (and showing you how to)