Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 28th, 2004, 11:47 AM
Registered User
 
Join Date: Jun 2003
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Grouping Nodes

Looking at the sample XML below ...

<Products>
     <ProductsItem>
          <Identifiers>
               <Identifier>
                    <Type>ECCN Nbr</Type>
                    <Value>12345</Value>
               </Identifier>
               <Identifier>
                    <Type>ECCN Nbr</Type>
                    <Value>43512</Value>
               </Identifier>
          </Identifiers>
     </ProductsItem>
     <ProductsItem>
          <Identifiers>
               <Identifier>
                    <Type>ECCN Nbr</Type>
                    <Value>54321</Value>
               </Identifier>
          </Identifiers>
     </ProductsItem>
     <ProductsItem>
          <Identifiers>
               <Identifier>
                    <Type>ECCN Nbr</Type>
                    <Value>12112</Value>
               </Identifier>
          </Identifiers>
     </ProductsItem>
</Products>

How can I select a group of ProductsItem nodes where the count of that group's Identifier nodes is less than say four? Looking at the above example I would want my result to be only the first two ProductsItem nodes because of count of the Identifier node within those first two ProductsItem nodes is equal to three.

I've been experimenting with ...

//ProductsItem[count(Identifiers/Identifier) &lt; 4]

Unfortunately, the avove expression brings back all ProductsItem nodes in the XML. I only want the first two ProductsItem node because the combined count of the first two ProductsItem/Identifiers/Identifier nodes is three which is essentially less than four.

Any help would be greatly appreciated.

Thanks,

Ben
Reply With Quote
  #2 (permalink)  
Old May 28th, 2004, 12:11 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Harrisburg, PA, USA.
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hello,

Are you saying that you only want the first three ProductsItem elements, and not all ProductsItem with less than three Identifiers?

Brian
Reply With Quote
  #3 (permalink)  
Old May 28th, 2004, 12:33 PM
Registered User
 
Join Date: Jun 2003
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Brian,

Because the XML will be constantly changing in terms of the number of ProductsItem nodes and corresponding child Identifier nodes, I want to be able to select as many ProductsItem nodes as possible without exceeding a maximum count of three Identifier nodes in the selected ProductsItem nodes. Wheew ...

Here is another example ... If I have ...

<Products>
     <ProductsItem>
          <Identifiers>
               <Identifier>
                    <Type>ECCN Nbr</Type>
                    <Value>43512</Value>
               </Identifier>
          </Identifiers>
     </ProductsItem>
     <ProductsItem>
          <Identifiers>
               <Identifier>
                    <Type>ECCN Nbr</Type>
                    <Value>54321</Value>
               </Identifier>
          </Identifiers>
     </ProductsItem>
     <ProductsItem>
          <Identifiers>
               <Identifier>
                    <Type>ECCN Nbr</Type>
                    <Value>12112</Value>
               </Identifier>
          </Identifiers>
     </ProductsItem>
     <ProductsItem>
          <Identifiers>
               <Identifier>
                    <Type>ECCN Nbr</Type>
                    <Value>21213</Value>
               </Identifier>
               <Identifier>
                    <Type>ECCN Nbr</Type>
                    <Value>21334</Value>
               </Identifier>
               <Identifier>
                    <Type>ECCN Nbr</Type>
                    <Value>21456</Value>
               </Identifier>
          </Identifiers>
     </ProductsItem>
</Products>

I only want the first three ProductsItem nodes because the total count of Identifier nodes in the first three ProductsItem nodes is equal to 3 which is less than four. Then, I would wan the next (4th postion) ProductsItem node by itself because it has a total of three Identifier nodes which is less than four.

Thanks for the quick response,

Ben
Reply With Quote
  #4 (permalink)  
Old May 28th, 2004, 10:34 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Harrisburg, PA, USA.
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hello,

You may be able to use the position() method to do this. Maybe try:

//ProductsItem[./Identifiers/Identifier/position() &lt; 4]

The way to think of what the position() method does is it groups all the results together and numbers them 1-n, and you can use this to limit the resultset in that manner. I'm a little rusty in my XML lately, so I may be a little off, but I hope this gets you in the right direction.

Brian
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Muenchian Grouping on individual nodes in xslt1.0 sudhish.sikhamani XSLT 9 July 1st, 2008 10:32 AM
Protect cells and allow grouping/un-grouping sfreuden Excel VBA 4 December 14th, 2006 08:01 AM
Get distinct values on *second* grouping of nodes. MissHenesy XSLT 4 October 23rd, 2006 10:34 AM
Grouping orphan nodes to paranet elements ROCXY XSLT 2 January 1st, 2006 07:11 AM
Grouping stand alone nodes inside an element Bala007 XSLT 2 December 30th, 2005 02:25 PM



All times are GMT -4. The time now is 09:56 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.