how to avoid the spaces b/w the nodes/elements in saxon parser/xalon parser
Вопрос
I have input like following snippet,
Input Snippet :
<div class="a">
<table>
<col width="4" />
<col width="8" />
<col width="5" />
<tbody>
<tr>
<td>ABC</td>
<td>DEF </td>
<td>GHI</td>
</tr>
</tbody>
</table>
</div>
<div class="x">
<table>
<col width="5" />
<col width="8" />
<col width="8" />
<tbody>
<tr>
<td>ABC</td>
<td>DEF </td>
<td>GHI</td>
</tr>
</tbody>
I am currently at table inside of the div class="a" tag, and I would like check either the immediately following sibling that is div and it's first child is table or nothing. I wrote the following XPath: ./../following-sibling::div[1]/node()[1] ) = 'table'
.
I am getting expected output in altova XMLSpy, but in saxon parser not giving exact output becasue there is some space between the <div>
and <table>
, and that space is treated as a text node.
How can I avoid the space between the tags, or are there any other solutions?
snippet Code :
<xsl:choose>
<xsl:when local-name(./../following-sibling::div[1]/node()[1] ) = 'table' ">
loagic-1
</xsl:when>
<xsl:otherwise>
logic-2
</xsl:otherwise>
</xsl:choose>
Решение
Although Ian's answer is correct, a cleaner solution is...
<xsl:when test="../following-sibling::div[1]/*[1]/self::table">
Also, if you didn't care about any intervening elements between the div and its table child, you could simplify to ...
<xsl:when test="../following-sibling::div[1]/table">
Другие советы
You need to use
<xsl:strip-space elements="*"/>
at the top level of your style sheet, to tell it to ignore whitespace-only text nodes when parsing.