XSLT : Return true if child exists in a specified path

mikus

New Member
How can I check if a node is exists in a specified path? For example, I have this xml:\[code\]<?xml version="1.0" encoding="UTF-8"?><books> <bookgroup name="group1"> <book name="BookName1"/> <book name="BookName2"/> <book name="BookName3"/> <book name="BookName4"/> <book name="BookName5"/> </bookgroup> <bookgroup name="group2"> <book name="BookName6"/> <book name="BookName7"/> </bookgroup> <selected> <book name="BookName2"/> <book name="BookName3"/> </selected></books>\[/code\]The desire output is to return true for since the child node : BookName2 and BookName 3 are exists in the selected tag and false for because none of its child is in the selected tag.This is what I have tried: \[code\] <xsl:template name="IsChildExist"> <xsl:param name="bookGroupName"/> <xsl:variable name="isExist"> <xsl:for-each select="//bookgoup[@NAME=$bookGroupName]/book"> <xsl:variable name="childNode" select="./@name"/> <xsl:choose> <xsl:when test="count(//selected/book[@name=$childNode])>0"> <xsl:value-of select="true()"/> </xsl:when> <xsl:otherwise> <xsl:value-of select="false()"/> </xsl:otherwise> </xsl:choose> </xsl:for-each> </xsl:variable> <xsl:value-of select="$isExist"/></xsl:template>\[/code\]But still fighting on the break in a for-each loop.Thank you in advance.
 
Back
Top