Retrieving All Customer element with ids contained in a list

I’m new to XSLT. In my XML invoice file, I have two elements partner and customer. There are 4 levels for a partner and each customer will be the last level which is 4 and associated with a person on level 3 (District) which in turn will be associated with a level 2 (Region). The corporate level is the top level. I have partner element with in which the relationship between the region and branches are listed. For each branch, I have a customer element which will be a sibling to the partner element. There will be number of transactions for each customer element. I have to do the following.

I know the parent element id. Suppose I search all the customers (with in the partner element) with that parent element id and I end up with a result of two customer ids.

Then with those customer ids, I’ll have to copy all the transactions (there may be two transactions for the first customer and 10 for the second customer which adds up to 12 transactions and I really don’t care which transaction is associated with which customer) which I can add to the summary row. I’m attaching the xml file that I’m trying to process and also a screen shot of how my html report would be. The branch summary row is the one I’m struggling with. I really appreciate any help or advice provided.
Invoice.xml (11.2 KB)

hard to tell what you want without the result html, or result xml posted.


<xsl:template match="Partner">
  <xsl:param name="pei" select="47"/>
  <xsl:for-each select="Hierarchy/Relationships/Element[parent_element_id = $pei]/customer_id">
    <xsl:for-each select="/document/Invoice/Customer[customer_id = current()/.]">
      <xsl:for-each select="Trans">
        <tr>
         Processing here.
  	    </tr>
	  </xsl:for-each>
    </xsl:for-each>  
  </xsl:for-each>
</xsl:template>

pass in parameter pei or replace with your variable. Default for pei should probably be ‘’

Sorry about not showing how the result should be. I’m trying to create tables to show the transaction summary for each customer (within a specific district) and a summary line that has details for all the customers in that district. In my sample file, I have two regions and hence two table are created. I’m having problem only with the summary row.

At the end of each report, there will be another table whose body will have the summary for district and the summary line itself will have all the transactions put together. If the region and district details are within a customer transaction, it’ll be easy for me to sort and group them together. But the relationship between a customer with a specific district and that districts relationship with a region are mentioned in a different element (Hierarchy). I don’t know how to group them based on their relatioship mentioned else where. I’d really appreciate your help.
Result.doc (106 KB)

couple possible ways I could see doing this.

  1. Use long xpaths:
    select="/document/Invoice/Customer"
    Selects all customers

select="/document/Invoice/Customer[customer_id = /document/Invoice/Partner/Hierarchy/Relationships/Element/customer_id]"
Selects all customers who have a relationship associated with them.

select="/document/Invoice/Customer[customer_id = /document/Invoice/Partner/Hierarchy/Relationships/Element[parent_element_id = $pei]/customer_id]/"
Selects all customers who have are in district $pei.

select=“count/document/Invoice/Customer[customer_id = /document/Invoice/Partner/Hierarchy/Relationships/Element[parent_element_id = $pei]/customer_id]/Trans)”
count of all Transaction of those customers.

select=“count(/document/Invoice/Customer[customer_id = /document/Invoice/Partner/Hierarchy/Relationships/Element[parent_element_id = $pei]/customer_id]/Trans[trans_type=‘CHRG’])”
Count all CHRG transactions for those customers.

  1. Create a temporary piece of xml incorporating your structure, which uses the xml structure properly. I created a small xsl file to do such a transformation. Then, finding/summing/calculating with this data is much easier. attached example
    temp.xml (4.75 KB)

I could have sworn I attached this…
tempa.xsl (1.6 KB)

THANKS A TON. I can’t thank you enough. I used your example of the Xpath and it worked like a charm. I looked at your attachments. You had created another XML file (I’m still in the begining of XML). I’m not sure if I can have both XML and html type output in the same transformation. My output is in html format. I’m kind of curious if we can create a nodeset like what is in your XML and then traverse through it to find the values of the transaction list? Anyways, thank you thank you thank you. It was a timely help and I really appreciate it.

regards
PV