[xsl] Counting items related by a linked list

Subject: [xsl] Counting items related by a linked list
From: "Joe K" <anotherquestion@xxxxxxxxxxx>
Date: Wed, 24 Mar 2004 09:21:17 -0800
I made a slight error in the original post of this message before.
I am making a correction, adding a few additional comments, and am reposting it.



The question: I would like to define a variable such that given the CItem ID, say 1003, I can get a count of all the AItems linked to it.


The answer for example below for CItemID = 2003 would be 3 because:

	<LinkItem>
	  <SourceID>104</SourceID>	BItem - not in count
	  <TargetID>1003</TargetID>
	</LinkItem>
	<LinkItem>
	  <SourceID>6</SourceID>	AItem - in count
	  <TargetID>1003</TargetID>
	</LinkItem>
	<LinkItem>
	  <SourceID>4</SourceID>	AItem - in count
	  <TargetID>1003</TargetID>
	</LinkItem>
	<LinkItem>
	  <SourceID>101</SourceID>	BItem - not in count
	  <TargetID>1003</TargetID>
	</LinkItem>
	<LinkItem>
	  <SourceID>2</SourceID>	AItem - in count
	  <TargetID>1003</TargetID>
	</LinkItem>



I have the following type of xml document:
Note:
1) All IDs are unique and can be any positive number
2) The link pairs below can link any item to any different Item.
3) CItems are always in the "Target" portion of the link table, but if AItem and BItem they can be in either position.
4) No item can be linked more than once to another item.
This means if there is a:
<LinkItem>
<SourceID>3</SourceID>
<TargetID>101</TargetID>
</LinkItem>
There cannot be a:
<LinkItem>
<SourceID>101</SourceID>
<TargetID>3</TargetID>
</LinkItem>



<TopLevel>


<AItem>
 <ID=1/>
 <Name=/>
</AItem>
<AItem>
 <ID=2/>
 <Name=/>
</AItem>
<AItem>
 <ID=3/>
 <Name=/>
</AItem>
<AItem>
 <ID=4/>
 <Name=/>
</AItem>
<AItem>
 <ID=5/>
 <Name=/>
</AItem>

<BItem>
 <ID=101/>
 <Name=/>
</BItem>
<BItem>
 <ID=102/>
 <Name=/>
</BItem>
<BItem>
 <ID=103/>
 <Name=/>
</BItem>
<BItem>
 <ID=104/>
 <Name=/>
</BItem>
<BItem>
 <ID=105/>
 <Name=/>
</BItem>
<BItem>
 <ID=106/>
 <Name=/>
</BItem>

<CItem>
 <ID=1001/>
 <Name=/>
</CItem>
<CItem>
 <ID=1002/>
 <Name=/>
</CItem>
<CItem>
 <ID=1003/>
 <Name=/>
</CItem>
<CItem>
 <ID=1004/>
 <Name=/>
</CItem>
<CItem>
 <ID=1005/>
 <Name=/>
</CItem>
<CItem>
 <ID=1006/>
 <Name=/>
</CItem>
<CItem>
 <ID=1007/>
 <Name=/>
</CItem>


<LinkItem> <SourceID>104</SourceID> <TargetID>1001</TargetID> </LinkItem> <LinkItem> <SourceID>104</SourceID> <TargetID>1003</TargetID> </LinkItem> <LinkItem> <SourceID>6</SourceID> <TargetID>1003</TargetID> </LinkItem> <LinkItem> <SourceID>105</SourceID> <TargetID>1002</TargetID> </LinkItem> <LinkItem> <SourceID>3</SourceID> <TargetID>101</TargetID> </LinkItem> <LinkItem> <SourceID>4</SourceID> <TargetID>1003</TargetID> </LinkItem> <LinkItem> <SourceID>102</SourceID> <TargetID>1</TargetID> </LinkItem> <LinkItem> <SourceID>101</SourceID> <TargetID>1003</TargetID> </LinkItem> <LinkItem> <SourceID>2</SourceID> <TargetID>1003</TargetID> </LinkItem>

</TopLevel>

_________________________________________________________________
Is your PC infected? Get a FREE online computer virus scan from McAfee. Security. http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963


Current Thread