
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Transforming XML
|
855
<td>Alice</td>
<td>Manager</td>
<td>12</td>
</tr>
<tr>
<td>Chas</td>
<td>Salesman</td>
<td>3</td>
</tr>
<tr>
<td>Rutherford</td>
<td>CEO</td>
<td>27</td>
</tr>
</tbody>
</table>
</p>
</body>
</html>
To generate comma-delimited output, use PersonnelCSV.xsl and Personnel.xml; the
stylesheet is shown here:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xsl:output method="text" encoding="UTF-8"/>
<xsl:template match="/">
<xsl:for-each select="Personnel">
<xsl:for-each select="Employee">
<xsl:for-each select="@name">
<xsl:value-of select="." />
</xsl:for-each>,<xsl:for-each select="@title">
<xsl:value-of select="." />
</xsl:for-each>,<xsl:for-each select="@companyYears">
<xsl:value-of select="." />
</xsl:for-each>
<xsl:text> 
</xsl:text>
</xsl:for-each>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
The output from the PersonnelCSV.xsl stylesheet is shown here:
Bob,Customer Service,1
Alice,Manager,12
Chas,Salesman,3
Rutherford,CEO,27
Discussion
There are many overrides for the XslCompiledTransform.Transform method. Since
XmlResolver is an abstract class, you need to use either the XmlUrlResolver or the