I have a rather flat table that looks like
<tr>
<td class="tableResultsA" nowrap>1</td>
<td class="tableResultsA" nowrap><A HREF="docs/123456" target="_blank">Title</A></td>
<td class="tableResultsA" nowrap>SNIPPET</td>
<td class="tableResultsA" nowrap>Date</td>
<td class="tableResultsA" nowrap>Category</td>
</tr>
<tr>
<td class="tableResultsB" nowrap>1</td>
<td class="tableResultsB" nowrap><A HREF="docs/678901" target="_blank">Title</A></td>
<td class="tableResultsB" nowrap>SNIPPET</td>
<td class="tableResultsB" nowrap>Date</td>
<td class="tableResultsB" nowrap>Category</td>
</tr>
I need to create a document out of this data, consisting of URL, Title and Snippet.
I’ve set my root result node to this:
<scope>
<xsl:value-of select>"//td[@class='tableResultsA'][2] | //td[@class='tableResultsB'][2]"
</scope>
For my document, I have the following:
<xsl:template match="//td">
<document url="{a/@href}">
<content name="title">
<xsl:value-of select="a" />
</content>
<content name="snippet">
<xsl:value-of select="//td[@class='tableResultsA'][3] | //td[@class='tableResultsB'][3]" />
</content>
</document>
</xsl:template>
The problem is the snippet. I’m getting the exact same result in my snippet output so it isn’t traversing the data. I’m not an XPath expert. I’m wondering if following or following-sibling would work but I haven’t been able to find a good example for them anywhere.
Any help would be appreciated.
This transformation:
when applied on the corrected (to become well-formed XML document) provided input:
produces the wanted, correct result: