0

I have an XML file. I want to convert it to HTML file and represent it like an HTML table using my C++ application. Is there any C++ library which I can use to parse the XML file and create an HTML file?

Example:

<breakfast_menu>
<food>
    <name>Belgian Waffles</name>
    <price>$5.95</price>
    <description>
   Two of our famous Belgian Waffles with plenty of real maple syrup
   </description>
    <calories>650</calories>
</food>
<food>
    <name>Strawberry Belgian Waffles</name>
    <price>$7.95</price>
    <description>
    Light Belgian waffles covered with strawberries and whipped cream
    </description>
    <calories>900</calories>
</food>
<food>
    <name>Berry-Berry Belgian Waffles</name>
    <price>$8.95</price>
    <description>
    Belgian waffles covered with assorted fresh berries and whipped cream
    </description>
    <calories>900</calories>
</food>

I want to give this file to my application and it should output an HTML file in which the entries are represented in table form.

name price description calories
Belgian Waffle 5.95 Two of our famous Belgian Waffles with plenty of real maple syrup 650
tue2017
  • 49
  • 7

1 Answers1

0

XSLT to convert input XML into HTML table.

XSLT

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output indent="yes" method="html"/>

    <xsl:template match="/breakfast_menu">
        <table border="1">
            <thead>
                <tr>
                    <th>name</th>
                    <th>price</th>
                    <th>description</th>
                    <th>calories</th>
                </tr>
            </thead>
            <tbody>
                <xsl:for-each select="food">
                    <tr>
                        <td><xsl:value-of select="name"/></td>
                        <td><xsl:value-of select="price"/></td>
                        <td><xsl:value-of select="description"/></td>
                        <td><xsl:value-of select="calories"/></td>
                    </tr>
                </xsl:for-each>
            </tbody>
        </table>
    </xsl:template>
</xsl:stylesheet>
Yitzhak Khabinsky
  • 18,471
  • 2
  • 15
  • 21