Given this XML
<ContentBlock>
<Content>
<QuickStatus Balance="0" Credits="0" Trolley="600" Delivery="100" Available="-700" Pending="0" />
<TrolleyItems>
<TrolleyItem Description="Test Item 1" value="150" />
<TrolleyItem Description="Test Item 2" value="150" />
<TrolleyItem Description="Test Item 3" value="300" />
</TrolleyItems>
</Content>
</ContentBlock>
I need to check if each of the trolly items value attributes are under 800 and then show the Final delivery attribute if at least one of the items are under 800. But only need to show the Delivery value once.
My XSLT .xsl file code looks like this.
<xsl:for-each select="Content/TrolleyItems/TrolleyItem">
<xsl:if test="ContentBlock/Content/TrolleyItems/TrolleyItem/@value < 800">
<tr style="border-bottom: 1px dashed #000;">
<xsl:for-each select="Content/Final">
<td>Delivery Fee</td><td><xsl:value-of select="@Delivery"/></td>
</xsl:for-each>
</tr>
</xsl:if>
</xsl:for-each>
What I need is to output one item for the @Delivery attribute.
It will only show one time for example the answer will be: “Delivery Costs: 100”. So Delivery is only charged when the item value is less than 800
![enter image description here][1]
Thanks for the help.
The inner
xsl:ifandxsl:for-eachshouldn’t have the full path.All nodes within the
xsl:for-eachare relative to the xpath in theselect, and because you’re using relative paths (they don’t start with/or//) then you’re looking forWhat I think you’re looking for is something like this…
See this xmlplayground for a live demo
Update
Even more efficient…
Update
Based on the comment by the OP, maybe something more like this (bearing in mind that I assume your actual XML will be a lot more complex that you’re currently showing, so this is probably not exactly what you’re looking for)…