filter nodes by looking in "multiple grandchilds"

Here should go questions about transforming XML with XSLT and FOP.
thomasstock
Posts: 1
Joined: Thu Sep 06, 2007 5:54 pm

filter nodes by looking in "multiple grandchilds"

Post by thomasstock »

Hello all,
I realise my title isn't clear, but neither is this problem for me :wink:

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>
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.

Code: Select all

<xsl:variable name="matchedNodes" select="$matchedNodesPreLogisticFilter[child::node()/data[@alias = 'category'] = 'Retail'"></xsl:variable>
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.
jkmyoung
Posts: 89
Joined: Mon Mar 06, 2006 10:13 pm

Post by jkmyoung »

I can't entirely see your code in the code box, but I'm assuming you need a nested conditional braces
Try this xpath:
//product[productLogisticInfo/data[.='Retail']]
Post Reply