Selecting All elements using XPath

Hi, I had posted a message under this forum with title Retrieving All Customer element with ids contained in a list.

With the suggestions of Xpath, I was able to acheive most of what I wanted. But there is one more glitch that I’m not able to resolve. I have two elements partner and customer. There are 4 levels for a partner and each customer will be the last level which is level 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’m able to select all customers under specific district. I’m having trouble with selecting all customers under different districts, but those districts belonging to one region. When I have only one district in each region, it works perfectly. If I have two districts in the same region, it ignores the second district and gives the summary of only one district. I’m attaching a result doc that has the result when I have one district under each region and also when I have two districts under the same region. The result should have been a sum of both districts and displayed in the table row. I’m also attaching all my XSL files and XML file that I’m using. I’d really appreciate any help or suggestions made and it’d save my day.

PV (83.7 KB)

Again I advise against using XPath this way, as changing to a structure that actually represents the data’s parent child relationships works much better than using the linear table based relationship. It would make the code FAR MORE managable in the long term.

You already do use temporary xml variables, as evidenced by use of msxsl:node-set($BranchMFeeTransList) in your BranchTable.xsl file.

Anyways, the ugly xpath:

<xsl:parameter name=“pei”>39</xsl:variable>

<xsl:for-each select=“/document/Invoice/Partner/Hierarchy/Relationships/Element[parent_element_id =$pei]”>

<xsl:for-each select=“/document/Invoice/Partner/Hierarchy/Relationships/Element[parent_element_id = /document/Invoice/Partner/Hierarchy/Relationships/Element[parent_element_id =$pei]/element_id]”>

<xsl:for-each select=“/document/Invoice/Customer[customer_id = (/document/Invoice/Partner/Hierarchy/Relationships/Element[parent_element_id = /document/Invoice/Partner/Hierarchy/Relationships/Element[parent_element_id =$pei]/element_id]/customer_id) ]”>

… now if you created a temporary structure the xpath would be much simpler.
something like:
<xsl:for-each select=“msxsl:node-set(someVariable)/Corporate/District[element_id=”$pei]">

<xsl:for-each select=“Region/Customer”>

you could make the xpath text smaller by using relative xpaths (eg …/, but may not be as easily understandable.

Customer ‘Element’ Elements
<xsl:for-each select=“/document/Invoice/Partner/Hierarchy/Relationships/Element[parent_element_id = …/Element[parent_element_id =$pei]/element_id]”>

Customer ‘Customer’ Elements
<xsl:for-each select=“/document/Invoice/Customer[customer_id = (…/Partner/Hierarchy/Relationships/Element[parent_element_id = …/Element[parent_element_id =$pei]/element_id]/customer_id) ]”>

It worked very nicely (though was confusing initially with such a long XPath). That was a timely help. Thank you so much.

best regards