XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Conferences Close Tree View
+ Stylus Studio Feature Requests (1192)
+ Stylus Studio Technical Forum (14621)
+ Website Feedback (249)
- XSLT Help and Discussion (7625)
-> + How to substitute element or t... (2)
-> + Xalan support in x16? (2)
-> + The context item for axis step... (5)
-> - ASP to XSL (1)
-> + xsl report, with xml feed, SVG... (7)
-> + XSLT code to transform CSV typ... (2)
-> + Make xstl file working in brow... (4)
-> + identity template, result-docu... (6)
-> - identity template and xsl:resu... (1)
-> + java.lang.RuntimeException: Er... (5)
-> + How to check matching parenthe... (2)
-> - Error only on using xalan:eval... (1)
-> + XSLT not displaying SOAP respo... (2)
-> + How do i delete the node from ... (2)
-> + How to break xslt lines to mak... (4)
-> - Marge node using attribute val... (1)
-> - Replce utf to unicode using xs... (1)
-> - getting different instances of... (1)
-> + XML to Flat (4)
-> + non breaking space   in e... (2)
-- [1-20] [21-40] [41-60] Next
+ XQuery Help and Discussion (2016)
+ Stylus Studio FAQs (159)
+ Stylus Studio Code Samples & Utilities (364)
+ Stylus Studio Announcements (113)
Topic  
Postnext
david knightSubject: selecting data into node set between two values
Author: david knight
Date: 30 Nov 2007 11:17 AM
Sorry if this is an extremely simple question, but I'm about as new to XML/XSL as you can be. I have the following XML, and need to select the data into chunks based upon a "change item" node having an "action_name" of "Create Order". So, in this data, there would be three chunks: one before the first create order, one between the two create orders and then the remaining data. I just can't figure out how to match it.

<?xml version="1.0" encoding="UTF-8" ?>
<transaction>
<change_history>
<change_item action_var_name="_open_quote_process" action_name="Open Quote" />
<change_item action_var_name="save_quote" action_name="Save" change_date="2007-11-29 15:38:35">
<discount_line document_number="2" old_value="10.0" new_value="0.0" />
<discount_line document_number="6" old_value="10.0" new_value="0.0" />
</change_item>
<change_item action_var_name="_update_line_items" action_name="Update Price" change_date="2007-11-29 15:38:41">
<marginPercentage document_number="6" old_value="15.6" new_value="24.0" />
</change_item>
<change_item action_var_name="submit_quote" action_name="Finalize Quote" change_date="2007-11-29 15:38:46">
<status_quote document_number="1" old_value="Pending" new_value="Submitted" />
<submittedDate_quote document_number="1" old_value="" new_value="2007-11-29 15:38:45" />
<expirationDate_quote document_number="1" old_value="" new_value="2007-12-29 15:38:45" />
<quoteType_quote document_number="1" old_value="Draft" new_value="Final" />
</change_item>
<change_item action_var_name="createOrder_quote" action_name="Create Order" change_date="2007-11-29 15:38:49" >
<status_quote document_number="1" old_value="Submitted" new_value="Creating Order" />
<submittedDate_quote document_number="1" old_value="2007-11-29 15:38:45" new_value="2007-11-29 00:00:00" />
<expirationDate_quote document_number="1" old_value="2007-12-29 15:38:45" new_value="2007-12-29 00:00:00" />
</change_item>
<change_item action_var_name="_open_quote_process" action_name="Open Quote" change_date="2007-11-29 15:44:38" />
<change_item action_var_name="submitOrder_quote" action_name="Submit Order" change_date="2007-11-29 15:45:07">
<status_quote document_number="1" old_value="Creating Order" new_value="Order Submitted" />
<poNumber_quote document_number="1" old_value="" new_value="12345652" />
<poDate_quote document_number="1" old_value="" new_value="2007-11-29 00:00:00" />
</change_item>
<change_item action_var_name="_open_quote_process" action_name="Open Quote" change_date="2007-11-29 15:46:32" />
<change_item action_var_name="revise_quote" action_name="Revise" change_date="2007-11-29 15:46:36">
<revisionNumber_quote document_number="1" old_value="2" new_value="3" />
<status_quote document_number="1" old_value="Order Submitted" new_value="Pending" />
<submittedDate_quote document_number="1" old_value="2007-11-29 00:00:00" new_value="" />
</change_item>
<change_item action_var_name="_open_quote_process" action_name="Open Quote" change_date="2007-11-29 15:47:53" />
<change_item action_var_name="revise_quote" action_name="Revise" change_date="2007-11-29 15:47:56" user_login="superuser">
<revisionNumber_quote document_number="1" old_value="3" new_value="4" />
</change_item>
<change_item action_var_name="submit_quote" action_name="Finalize Quote" change_date="2007-11-29 15:48:08">
<status_quote document_number="1" old_value="Pending" new_value="Submitted" />
<submittedDate_quote document_number="1" old_value="" new_value="2007-11-29 15:48:07" />
<expirationDate_quote document_number="1" old_value="2007-12-29 00:00:00" new_value="2007-12-29 15:48:07" />
</change_item>
<change_item action_var_name="createOrder_quote" action_name="Create Order" change_date="2007-11-29 15:48:10">
<status_quote document_number="1" old_value="Submitted" new_value="Creating Order" />
<submittedDate_quote document_number="1" old_value="2007-11-29 15:48:07" new_value="2007-11-29 00:00:00" />
<expirationDate_quote document_number="1" old_value="2007-12-29 15:48:07" new_value="2007-12-29 00:00:00" />
</change_item>
<change_item action_var_name="submitOrder_quote" action_name="Submit Order" change_date="2007-11-29 15:48:12" >
<status_quote document_number="1" old_value="Creating Order" new_value="Order Submitted" />
</change_item>
</change_history>
</transaction>

Posttop
James DurningSubject: selecting data into node set between two values
Author: James Durning
Date: 03 Dec 2007 09:45 AM
One way is to use generate-id.
Another way is to use key.
I like the key method personally:
<xsl:key name="CreateIndex" match="change_item_action" use="generate-id(preceding-sibling::change_item_action[
@action_name='Create Order'][1])"/>

1st chunk:
<xsl:for-each select="key('CreateIndex', '')">
...
</xsl:for-each>

Subsequent chunks
<xsl:for-each select="change_item_action[
@action_name='Create Order']>
<Chunk>
<xsl:for-each select="key('CreateIndex', generate-id())"/>
</Chunk>
</xsl:for-each>

   
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.