i have developed an application in xsl. what i want to do is i m searching the xml file based on a search.and based on that search im creating one tree like structure. in this tree structure i need the count of siblings in each level. im not getting the count exactly the same
the xslt file
-----------------
Expand|Select|Wrap|Line Numbers
- <?xml version="1.0" encoding="UTF-8"?>
- <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:vml="urn:schemas-microsoft-com:vml">
- <xsl:output method="xml" omit-xml-declaration="yes" />
- <xsl:param name ="param3">DateChkForENT</xsl:param>
- <xsl:template match="/">
- <html xmlns:vml="urn:schemas-microsoft-com:vml">
- <head>
- <object id="VMLRender" classid="CLSID:10072CEC-8CC1-11D1-986E-00A0C955B42E">
- </object>
- <style>
- vml\:* { behavior: url(#VMLRender) }
- </style>
- </head>
- <body>
- <xsl:call-template name="object" />
- </body>
- </html>
- </xsl:template>
- <xsl:template name="object">
- <xsl:for-each select="//objects/object[@businessrule = $param3 and .//macro/param[@name = 'context'or @name = 'objectname'] ]">
- <xsl:choose>
- <xsl:when test="@businessrule = $param3">
- FOR UP BUSINESS RULE
- <xsl:call-template name="uprelatedBR">
- <xsl:with-param name="referncesToMe" select="//objects/object[.//macro[starts-with(@name, concat('BusinessRule.',$param3) )]]"/>
- <xsl:with-param name="x">500</xsl:with-param>
- <xsl:with-param name="y">500</xsl:with-param>
- </xsl:call-template>
- </xsl:when>
- </xsl:choose>
- </xsl:for-each>
- </xsl:template>
- <!--Look For UP Relation-->
- <xsl:template name="uprelatedBR">
- <xsl:param name="paramLevelRefCount"/>
- <xsl:param name="referncesToMe"/>
- <xsl:param name="x" />
- <xsl:param name="y" />
- <!-- calculate the number of references of references-->
- <xsl:variable name="grandParentCount">
- <xsl:call-template name="levelReferences">
- <xsl:with-param name="nodes" select="$referncesToMe"/>
- </xsl:call-template>
- </xsl:variable>
- <font color="blue">
- <xsl:value-of select="$grandParentCount"/>
- </font>
- <!-- calculate the number of references-->
- <xsl:variable name="levelRefCount">
- <xsl:choose>
- <xsl:when test="$paramLevelRefCount">
- <xsl:value-of select="$paramLevelRefCount"/>
- </xsl:when>
- <xsl:otherwise>
- <!--this will execute only the first time the template is called-->
- <xsl:value-of select="count($referncesToMe)"/>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:variable>
- <xsl:call-template name="drawNode">
- <xsl:with-param name="nodesToDraw" select="$referncesToMe"/>
- <xsl:with-param name="currentNodePosition">1</xsl:with-param>
- <xsl:with-param name="levelRefCount" select="$levelRefCount"/>
- <xsl:with-param name="grandParentCount" select="$grandParentCount"/>
- <xsl:with-param name="levelOffset">0</xsl:with-param>
- <xsl:with-param name="x" select="$x - (($levelRefCount * 80) div 2)"/>
- <xsl:with-param name="y" select="$y"/>
- </xsl:call-template>
- </xsl:template>
- <xsl:template name="drawNode">
- <xsl:param name="nodesToDraw"/>
- <xsl:param name="currentNodePosition"/>
- <xsl:param name="levelRefCount"/>
- <xsl:param name="grandParentCount"/>
- <xsl:param name="levelOffset"/>
- <xsl:param name="x" />
- <xsl:param name="y" />
- <xsl:variable name="currentBRName" select="$nodesToDraw[position() = $currentNodePosition]/@businessrule"/>
- <xsl:variable name="currentBRReferences" select="//objects/object[.//macro[starts-with(@name, concat('BusinessRule.',$currentBRName) )]]"/>
- <!--calculate the x position of the current box and print-->
- <xsl:variable name="myX" select="$x + (80 * ($currentNodePosition - 1))" />
- <xsl:variable name="myY" select="$y - 80" />
- <vml:roundrect arcsize="20%" style="{concat('LEFT:', $myX ,'px;WIDTH:60px;POSITION:absolute;TOP:' , $myY , 'px;HEIGHT:60px')}"
- strokecolor="#F0F3F3" fillcolor="#F0F3F3" coordsize="21600,21600">
- <vml:fill type="gradient" method="linear sigma" angle="180" color2="#CCCCCC" color="#ffffff"></vml:fill>
- <xsl:value-of select="$currentBRName"/>
- <xsl:value-of select="$x"/>
- <br></br>
- <xsl:value-of select="$levelRefCount"/>
- </vml:roundrect>
- <xsl:if test="$currentNodePosition < count($nodesToDraw)">
- <xsl:call-template name="drawNode">
- <xsl:with-param name="nodesToDraw" select="$nodesToDraw"/>
- <xsl:with-param name="currentNodePosition" select="$currentNodePosition + 1"></xsl:with-param>
- <xsl:with-param name="levelRefCount" select="$levelRefCount"/>
- <xsl:with-param name="grandParentCount" select="$grandParentCount"/>
- <xsl:with-param name="levelOffset" select="count($currentBRReferences) + $levelOffset"/>
- <xsl:with-param name="x" select="$x"/>
- <xsl:with-param name="y" select="$y"/>
- </xsl:call-template>
- </xsl:if>
- <xsl:if test="$currentBRReferences">
- <xsl:variable name="skipX" select="$levelOffset * 80"/>
- <xsl:call-template name="uprelatedBR">
- <xsl:with-param name="referncesToMe" select="$currentBRReferences"/>
- <xsl:with-param name="paramLevelRefCount" select="$grandParentCount"/>
- <xsl:with-param name="x" select="500 + $skipX"/>
- <xsl:with-param name="y" select="$myY"/>
- </xsl:call-template>
- </xsl:if>
- </xsl:template>
- <xsl:template name="levelReferences">
- <xsl:param name="nodes" />
- <!--list of businessrule calls-->
- <xsl:variable name="set1" select="//objects/object//macro[starts-with(@name, 'BusinessRule.')]"/>
- <!--set of business rule calls to look for-->
- <xsl:variable name="set2" select="$nodes"/>
- <!--concatenated business rule calls-->
- <xsl:variable name="currentRuleNames">
- <xsl:for-each select="$set2">
- <xsl:value-of select="concat(',',@businessrule)"/>
- </xsl:for-each>
- </xsl:variable>
- <!--count for set1 references to currentRuleNames-->
- <xsl:value-of select="count($set1[contains($currentRuleNames,concat(',',substring-after(@name, '.')))])"/>
- </xsl:template>
- </xsl:stylesheet>
---------------------
Expand|Select|Wrap|Line Numbers
- <objects>
- <object businessrule="Time Check" name="ENT" onsave="yes">
- <macro name="BusinessRule.Check">
- <param name="context"></param>
- </macro>
- </object>
- <object businessrule="Chk" name="Patients Information">
- <macro name="BusinessRule.newtest">
- <param name="context"></param>
- </macro>
- </object>
- <object businessrule="DateChkForENT" name="ENT">
- <macro name="BusinessRule.e">
- <param name="context"></param>
- </macro>
- <macro name="BusinessRule.f">
- <param name="context"></param>
- </macro>
- </object>
- <object businessrule="dddd" name="BED">
- <macro name="BusinessRule.DateChkForENT">
- <param name="context"></param>
- </macro>
- </object>
- <object businessrule="ss" name="ENT">
- <macro name="BusinessRule.newtest">
- <param name="context"></param>
- </macro>
- </object>
- <object businessrule="q" name="BED">
- <macro name="BusinessRule.ss">
- <param name="context"></param>
- </macro>
- </object>
- <object businessrule="newtest" name="Doctors Schedule">
- <macro name="BusinessRule.DateChkForENT">
- <param name="context"></param>
- </macro>
- </object>
- <object businessrule="Check" name="ENT" onsave="yes">
- <macro name="BusinessRule.DateChkForENT">
- <param name="context"></param>
- </macro>
- </object>
- <object businessrule="a" name="Doctors Schedule">
- <macro name="BusinessRule.dddd">
- <param name="context"></param>
- </macro>
- </object>
- <object businessrule="b" name="Registered Patients">
- <macro name="BusinessRule.dddd">
- <param name="context"></param>
- </macro>
- </object>
- <object businessrule="u" name="Registered Patients">
- <macro name="BusinessRule.b">
- <param name="context"></param>
- </macro>
- </object>
- <object businessrule="X" name="ENT">
- <macro name="BusinessRule.a">
- <param name="context"></param>
- </macro>
- </object>
- <object businessrule="y" name="">
- <macro name="BusinessRule.a">
- <param name="context"></param>
- </macro>
- </object>
- <object businessrule="p" name="">
- <macro name="BusinessRule.ss">
- <param name="context"></param>
- </macro>
- </object>
- <object businessrule="r" name="">
- <macro name="BusinessRule.p">
- <param name="context"></param>
- </macro>
- </object>
- </objects>
-------------
Expand|Select|Wrap|Line Numbers
- FOR UP BUSINESS RULE 5dddd380
- 3newtest380
- 3Check380
- 30Time Check620
- 52Chk460
- 5ss460
- 51q420
- 2p420
- 20r460
- 13a300
- 5b300
- 50u540
- 30X380
- 3y380
- 3