OK, I have an XML document which comprises the results of two different reports:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="friends.xsl"?>
<root>
<report name="Type1">
<Datarow>
<Name>Fred</Name>
<Age>39</Age>
</Datarow>
<Datarow>
<Name>George</Name>
<Age>41</Age>
</Datarow>
</report>
<report name="Type2">
<Datarow>
<Name>Sheila</Name>
<Age>20</Age>
</Datarow>
<Datarow>
<Name>Susie</Name>
<Age>23</Age>
</Datarow>
</report>
</root>
I am transforming this with (in this example) a simple XSL file using XSL 1.0.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="report[@name='Type1']">
<table>
<tr><td>Name</td><td>Age</td></tr>
<xsl:apply-templates select="Datarow"/>
</table>
</xsl:template>
<xsl:template match="Datarow">
<tr><td> <xsl:value-of select="Name"/></td>
<td><xsl:value-of select="Age"/></td></tr>
</xsl:template>
</xsl:stylesheet>
My understanding is that the first template match statement sets the node pointer at the XML report node where the report name attribute is "Type1". I then have a apply templates select looking for Datarow. This matches my Datarow template which brings back the name and age details.
The problem is that it brings back the Name and Age for the Type1 report, formatted in a table as i specified, but then I get the text from the Type2 report node as unformatted text:
<div id="result_output">
<table style="border: solid 1px;">
<tbody><tr>
<td>Name</td>
<td>Age</td>
</tr>
<tr>
<td>Fred</td>
<td>39</td>
</tr>
<tr>
<td>George</td>
<td>41</td>
</tr>
</tbody></table>
Sheila
20
Susie
23
</div>
What am I doing wrong?
<report name="Type2">
. - michael.hor257k