Java Reference
In-Depth Information
<xsl:value-of select="@id"/>
</td>
<td>
<xsl:value-of select="name"/>
</td>
<td>
<xsl:value-of select="diagnosis"/>
</td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Using this stylesheet, the sample code transforms the XML into an HTML table
containing all the patients and their data. Rendered in a browser, the HTML table
should look like the one in
Figure 20-1
.
Figure 20-1
.
A common rendering of an HTML table
The process for using this XSL file to convert the XML to an HTML file is
straightforward, but every step can be enhanced with additional error checking and pro-
cessing. For this example, refer to the previous code in the solution section.
The most basic transformation steps are these:
1.
Read the XSL document into your Java application as a
Source
ob-
ject.
2.
Create a
Transformer
instance and provide your XSL
Source
instance for it to use during its operation.