hi all,
this is my xml:
<root>
<a>
<b>
<t>1</t>
</b>
<b>
<t>2</t>
</b>
</a>
</root>
i want to ask: thats tell me if any t exist but i want true answer onky if b exsit and he have t=1
tanks
hi all,
this is my xml:
<root>
<a>
<b>
<t>1</t>
</b>
<b>
<t>2</t>
</b>
</a>
</root>
i want to ask: thats tell me if any t exist but i want true answer onky if b exsit and he have t=1
tanks
The test you looking for is
//b/t[text() = '1']
This test can now be used in a template
as the match, in a for-each
loop as a selector or in a if
statement as the test - e.g.:
<xsl:template match="//b/t[text() = '1']">
<!-- all t children of b with a content of 1 -->
</xsl:template>
<xsl:for-each select="//b/t[text() = '1']">
<!-- all t children of b with a content of 1 -->
</xsl:for-each>
<xsl:if test="//b/t[text() = '1']">
<!-- This is the true case -->
</xsl:if>
Note:
//
with something more appropriate to avoid inefficiencies. text()
function concatenates the textual content of all descendant nodes, i.e. only use it in the above way if you can be sure that there are no further descendants.Use:
boolean(/*/*/b[t=1])
When evaluated against the provided XML document, the result is:
true()
Remember: Always try to avoid the //
abbreviation, because it causes extremely inefficient traversing of the whole (sub) tree rooted at the context node.