<xsl:template match="location">
<xsl:if test="not(preceding::location)">
<table>
<tr>
<th>Name</th>
<th>City</th>
<th>State</th>
<th>Zip Code</th>
<th>Country</th>
</tr>
</xsl:if>
<tr>
<td><xsl:value-of select=".//name"/></td>
<td><xsl:value-of select=".//city"/></td>
<td><xsl:value-of select=".//state"/></td>
<td><xsl:value-of select=".//zip"/></td>
<td><xsl:value-of select=".//countdy"/></td>
</tr>
<xsl:if test="not(following::location)">
</table>
</xsl:if>
</xsl:template>
Is the any way to allow mismatched tags in XSLT… or is there another way to achieve the same desired effect?
Like Dimitre said, there is no way to allow mismatched tags in XSLT. There shouldn’t be a reason to have mismatched tags though.
Looking at your template, it looks like you’re trying to build an html table out of all the
<location>elements of your XML instance. You’re trying to open the table at the first<location>and trying to close the table at the last<location>.The easiest way to do this is to open your table at a higher level (parent/ancestor) and then populate the table with the
<location>data.Here’s a sample XML file that has 3
<location>s:Here’s a stylesheet that will create the table:
This is the output:
If for some reason you needed to create the
<table>at the first<location>, you could still do that. It would require more code though.The following stylesheet produces the same output as the first stylesheet: