Adding condition in xslt

tia_kamakshi
tia_kamakshi used Ask the Experts™
on
Hi,

I need help in modifying my condition in xsl

I have 3 param in my xsl
<xsl:param name="today" select="'19470815'" /> <!-- this is date in yyyyMMdd format -->

<xsl:param name="categoryID"/> <!-- This is CATEGORYID in xml file -->
<xsl:param name="subCategoryID"/> <!-- This is SUBCATEGORYID in xml file -->


My current xsl looks for only subcategory and does not looks for category

I require, if category is passed as value 0 then list all categories result, if some category id is passed then result should display only for that category id only

if subcategory id is 0 than display result subcategories under mentioned categoryid only, if particular category id is passed than result should display values from that particular sub category, which comes under selected subcategory

if category and subcategory is 0 then display all results

today parameter is passed so that no past date result should display

Please guide me in fixing this xslt. My xml and xslt are attached

Many Thanks
<xsl:choose>
	<xsl:when test="$type = 'open' ">

		<xsl:for-each select="//SUMMARYNODE[SUMMARY/SUBCATEGORYID = $subCategoryID and SUMMARY/FORMATTEDDATE >= $today]  ">
			<xsl:sort select="SUMMARY/FORMATTEDDATE " />
			SOME STUFF
		</xsl:for-each>
		<xsl:if test="count(//SUMMARYNODE[SUMMARY/SUBCATEGORYID = $subCategoryID and SUMMARY/FORMATTEDDATE >= $today] ) >= 1 ">
			SOME MORE STUFF
		</xsl:if>
		<xsl:if test="not (count(//SUMMARYNODE[SUMMARY/SUBCATEGORYID = $subCategoryID and SUMMARY/FORMATTEDDATE >= $today] )>=1) ">
			NO RECORDS AVAILABLE
		</xsl:if>

	</xsl:when>

</xsl:choose>

<root>

	<SUMMARYNODE>
		<SUMMARY>			
			<CATEGORY CATEGORYID="2">OPERATIONS PROCUREMENT</CATEGORY>
			<SUBCATEGORYID>4</SUBCATEGORYID>			
		</SUMMARY>
		
	</SUMMARYNODE>
	
	
	<SUMMARYNODE>
		<SUMMARY>			
			<CATEGORY CATEGORYID="2">XYZ</CATEGORY>
			<SUBCATEGORYID>6</SUBCATEGORYID>			
		</SUMMARY>
				
	</SUMMARYNODE>
	
	<SUMMARYNODE>
		<SUMMARY>			
			<CATEGORY CATEGORYID="5">ABC</CATEGORY>
			<SUBCATEGORYID>8</SUBCATEGORYID>			
		</SUMMARY>
			
	</SUMMARYNODE>

</root>

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Information Architect
Top Expert 2006
Commented:
Here is the XPath that selects the SUMMARY elements that you look for
//SUMMARY[CATEGORY/@CATEGORYID = $categoryID or $categoryID = 0][SUBCATEGORYID = $subCategoryID or $subCategoryID = 0]
you can use this in a test any way you want

if you need to add the date restriction, simply add a predicate
//SUMMARY[CATEGORY/@CATEGORYID = $categoryID or $categoryID = 0][SUBCATEGORYID = $subCategoryID or $subCategoryID = 0][SUMMARY/FORMATTEDDATE >= $today]

Author

Commented:
Great Many Thanks
Gertone (Geert Bormans)Information Architect
Top Expert 2006

Commented:
welcome

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial