We've created an XML, but the output of the XML isn't convincing.
We therefore extend XML generation by converting the XML into HTML code. For this we use an XSL template.
For the XSL template, we create a constant group called XSL Templates and a multiline string constant called Material.
This text constant gets the following content:
<?xml version="1.0" encoding="UTF-8"?>
<html xsl:version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<body style="font-family:Arial;font-size:12pt;background-color:#EEEEEE">
<xsl:for-each select="Root">
<xsl:value-of select="@Product" disable-output-escaping="no"/>
</xsl:for-each>
<br/>
<br/>
<table>
<tr>
<td width="100px">ID</td>
<td width="100px">Number</td>
<td width="300px">Description</td>
<td width="200px">Position price</td>
</tr>
<xsl:for-each select="Root/Material">
<tr>
<td width="100px">
<xsl:value-of select="@ID" disable-output-escaping="no"/>
</td>
<td width="100px">
<xsl:value-of select="@NumberOf" disable-output-escaping="no"/>
</td>
<td width="300px">
<xsl:value-of select="@Description" disable-output-escaping="no"/>
</td>
<td width="200px">
<xsl:value-of select="@PositionPrice" disable-output-escaping="no"/>
</td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
The DOMDocument object now allows the linking of the contained XML data with an XSL template like this one for generating HTML code. To do this, we change the program code in the Click event. We also create a feature HTMLOutput of type String in the Start class to store the HTML code. A new form called [Interface Result] is also designed to output the HTML code.
Private Function Click() As Void
If Product.ValidChildElements = False Then
MsgBox(Messages.[Configuration invalid], TCEServer.MsgBoxStyle.Critical,, MainForm.hwnd)
Return
End If
Dim DOM As MSXML2.DOMDocument
DOM := Interface
Dim DOMXSL As New MSXML2.DOMDocument
DOMXSL.loadXML([XSL Templates].Material)
HTMLOutput := DOM.transformNode(DOMXSL)
[Interface Result].Show
End Function
The form receives a WebBrowser control from the TCE Multimedia Controls type library.
Set the control to fill the HTML property with the HTMLOutput feature and initialize the UseHTML property with True.
You should get the following result:
(knowledge base Tutorial Stage 15)