1

My apologies if this has already been asked and answered, but after about 8 hrs of searching, I'm knackered.

Displaying the attribute values of a single xml file in an HTML table is straight forward using xsl, css and Microsoft.XMLDOM. Here's where I'm stumped... the HTML table needs to display additional attribute values from several other XML files, synchronizing those newly added values with existing HTML table row data. An analogy might be using Excel vlookup to populate cells from several other tabs.

For example: File1.xml

 <?xml version="1.0" encoding="UTF-8"?>
    <Fields>
        <field_tag field_name="ABC" data_type="CHAR" field_length="10" descriptionText="string" />
        ...
    </Fields>

File2.xml (Note that field_name is the common attribute between File1 and File2.)

 <?xml version="1.0" encoding="UTF-8"?>
    <Tables">
        <table_tag table_name="table1" field_name="ABC"/>
        ...
    </Tables>

File3.xml (Note that table_name is the common attribute between File2 and File3.)

 <?xml version="1.0" encoding="UTF-8"?>
    <Tables_List">
        <table_List_tag table_name="table1" descriptionText="string"/>
        ...
    </Tables_List>

The end result needs to be an html table, with each row having these values from the XML sources:

    <table>
      <tr>
        <th>Table Name</th>
        <th>Field Name</th>
        <th>  ...</th>
     </tr>
     <xsl:for-each select="?? corresponding tag name in XML files">
     <tr>       
       <td>
        <xsl:value-of select="@table_name"/>
       </td>
       <td>
         <xsl:value-of select="@field_name"/>
       </td>
       <td>
         <xsl:value-of select="@data_type"/>
       </td>
       <td>
         <xsl:value-of select="@field_length"/>
       </td>
       <td>
         <xsl:value-of select="@descriptionText"/>
       </td>
     </tr>
     </xsl:for-each>
   </table>
RickEEE
  • 11
  • 2
  • So which XSLT version, which XSLT processor do you want to use? But even with XSLT 1 you can use e.g. `document('file2.xml')//field_tag[@field_name = current()/@field_name]/@table_name` to select from the second file where you process the first file's `field_tag` elements with a matching template or for-each. – Martin Honnen Dec 28 '17 at 19:55
  • Thanks, Martin. I'm currently using XSLT 1.0. Interesting reply, I will tinker with that. I neglected to mention that the xml source files are located on a web server, so http:///File2.xml. I suspect that will make no difference. – RickEEE Dec 28 '17 at 20:27
  • In theory you can use `document('http://example.com/file2.xml')`, if you run the script inside of IE or Edge then unless your HTML with the script also comes from `http://example.com` you will run into problems with the same origin policy. – Martin Honnen Dec 28 '17 at 20:57
  • You can read xml into a DataTable : DataTable dt = new DataTable(); dt.ReadXml("filename"); Then use following code to convert DataTable to html : https://stackoverflow.com/questions/19682996/datatable-to-html-table – jdweng Dec 29 '17 at 02:22

0 Answers0