filter nodes by looking in "multiple grandchilds"
Posted: Thu Sep 06, 2007 6:21 pm
Hello all,
I realise my title isn't clear, but neither is this problem for me
First of all, here's my XML (I simplified it a bit):
So I have multiple product nodes which each have 0, 1 or more "productLogisticInfo" child nodes.
What I'm trying to do, is to filter out a nodeset of these product nodes by looking if one of their child nodes has a "data" node containing a certain category.
So if I look for "Retail" it should return the "product A" and "product B" nodes. Looking for "Food Service" should return the product B node.
I have partially solved this problem, but my current solution only checks the first "productLogisticInfo" node of each product, and ignores the other ones.
This is what I currently use to filter a nodeset: (again, I simplified my real code)
$matchedNodesPreLogisticFilter contains a node set of products.
This piece of code would only return the second product since the first product's "Retail" category is in the second child productLogisticInfo node.
How can I make it return both product nodes?
Thank you in advance.
I realise my title isn't clear, but neither is this problem for me

First of all, here's my XML (I simplified it a bit):
Code: Select all
<products>
<product id="1185" nodeName="product A">
<productLogisticInfo id="1191">
<data alias="category">Industry</data>
</productLogisticInfo>
<productLogisticInfo id="1192">
<data alias="category">Retail</data>
</productLogisticInfo>
</product>
<product id="2185" nodeName="product B">
<data alias="productNumber">123</data>
<productLogisticInfo id="2191">
<data alias="category">Retail</data>
</productLogisticInfo>
<productLogisticInfo id="2192">
<data alias="category">Industry</data>
</productLogisticInfo>
<productLogisticInfo id="2192">
<data alias="category">Food Service</data>
</productLogisticInfo>
</product>
</products>
What I'm trying to do, is to filter out a nodeset of these product nodes by looking if one of their child nodes has a "data" node containing a certain category.
So if I look for "Retail" it should return the "product A" and "product B" nodes. Looking for "Food Service" should return the product B node.
I have partially solved this problem, but my current solution only checks the first "productLogisticInfo" node of each product, and ignores the other ones.

This is what I currently use to filter a nodeset: (again, I simplified my real code)
$matchedNodesPreLogisticFilter contains a node set of products.
Code: Select all
<xsl:variable name="matchedNodes" select="$matchedNodesPreLogisticFilter[child::node()/data[@alias = 'category'] = 'Retail'"></xsl:variable>
How can I make it return both product nodes?
Thank you in advance.