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)
-> + Use of before and after string (3) Sticky Topic
-> - How do I substitute element ty... (1)
-> + How does one add working days ... (4)
-> - Help, I have existing XLT and... (1)
-> + Need help on XSLT issue - (2)
-> + EDI to XML Conversion (7)
-> - XML To JSON Conversion using X... (1)
-> + Formatting Paragraphs to same ... (2)
-> - Grouping of records (1)
-> + Problems with xsd 1.1 (4)
-> + XML to HL7 mapping (3)
-> + XSLT 3 and Iterate (2)
-> + XSL-FO to PDF preview (3)
-> + java.lang.RuntimeException: Er... (2)
-> + Create Acroforms with Stylus X... (2)
-> + How to change XSLT parameter s... (3)
-> + how to change format of the da... (2)
-> + Search "Next 8 Results " doesn... (2)
-> - Support for Git (1)
-> + newbee (8)
-- [1-20] [21-40] [41-60] Next
+ XQuery Help and Discussion (2017)
+ Stylus Studio FAQs (159)
+ Stylus Studio Code Samples & Utilities (364)
+ Stylus Studio Announcements (113)
Topic  
Postnext
Simon CowleySubject: Grouping without For-Each
Author: Simon Cowley
Date: 22 Oct 2007 02:44 AM
Hi all

I am still having a problem with sequential processing of some xml and grouping by ID. I have a source with a Trans node followed by TransItem nodes. I am able to read the preceding sibling value of these but I do not know how to group and wrap them as seperate transactions in my output. Each time I try something it loses the sequential order of the source file.

All examples I have seen are using a For-Each loop.

Many thanks

Simon

********************************************************************
Source XML***

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="C:\Documents and Settings\scowley\My Documents\SAP\XI\XML\MobilStandard.xslt"?>
<n1:MobilStandard xmlns:n1="urn:simon.com:co:xi:process:fuel">
<Trans>
<Docket>1234</Docket>
<Fee>Fee</Fee>
<Amount>10</Amount>
</Trans>
<TransItem>
<ID/>
<Product>ULP</Product>
<Amount>10</Amount>
</TransItem>
<TransItem>
<ID/>
<Product>ULP</Product>
<Amount>50</Amount>
</TransItem>
<Trans>
<Docket>1235</Docket>
<Fee>Fee1</Fee>
<Amount>10</Amount>
</Trans>
<TransItem>
<ID/>
<Product>ULP</Product>
<Amount>70</Amount>
</TransItem>
</n1:MobilStandard>


******************************************************************
XSLT mapping ***

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:n1="urn:simon.com:co:xi:process:fuel" xmlns:fn="http://www.w3.org/2005/xpath-functions" exclude-result-prefixes="xsi xs n1 fn">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<n1:MobilStandard>
<xsl:apply-templates/>
</n1:MobilStandard>
</xsl:template>
<xsl:template match="n1:MobilStandard/Trans">
<Item>
<ID>
<xsl:value-of select="Docket"/>
</ID>
<Product>
<xsl:value-of select="Fee"/>
</Product>
<Amount>
<xsl:value-of select="Amount"/>
</Amount>
</Item>
</xsl:template>
<xsl:template match="n1:MobilStandard/TransItem">
<Item>
<ID>
<xsl:value-of select="preceding-sibling::Trans[1]/Docket"/>
</ID>
<Product>
<xsl:value-of select="Product"/>
</Product>
<Amount>
<xsl:value-of select="Amount"/>
</Amount>
</Item>
</xsl:template>
</xsl:stylesheet>


****************************************************************
Current output***

<?xml version="1.0" encoding="UTF-8"?>
<n1:MobilStandard xmlns:n1="urn:simon.com:co:xi:process:fuel">
<Item>
<ID>1234</ID>
<Product>Fee</Product>
<Amount>10</Amount>
</Item>
<Item>
<ID>1234</ID>
<Product>ULP</Product>
<Amount>10</Amount>
</Item>
<Item>
<ID>1234</ID>
<Product>ULP</Product>
<Amount>50</Amount>
</Item>
<Item>
<ID>1235</ID>
<Product>Fee1</Product>
<Amount>10</Amount>
</Item>
<Item>
<ID>1235</ID>
<Product>ULP</Product>
<Amount>70</Amount>
</Item>
</n1:MobilStandard>

*******************************************************************
Desired output***

<?xml version="1.0" encoding="UTF-8"?>
<n1:MobilStandard xmlns:n1="urn:simon.com:co:xi:process:fuel">
<Trans>
<Item>
<ID>1234</ID>
<Product>Fee</Product>
<Amount>10</Amount>
</Item>
<Item>
<ID>1234</ID>
<Product>ULP</Product>
<Amount>10</Amount>
</Item>
<Item>
<ID>1234</ID>
<Product>ULP</Product>
<Amount>50</Amount>
</Item>
</Trans>
<Trans>
<Item>
<ID>1235</ID>
<Product>Fee1</Product>
<Amount>10</Amount>
</Item>
<Item>
<ID>1235</ID>
<Product>ULP</Product>
<Amount>70</Amount>
</Item>
</Trans>
</n1:MobilStandard>

Postnext
(Deleted User) Subject: Grouping without For-Each
Author: (Deleted User)
Date: 22 Oct 2007 06:28 AM
Hi Simon,
this should work for you:

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:n1="urn:simon.com:co:xi:process:fuel"
xmlns:fn="http://www.w3.org/2005/xpath-functions" exclude-result-prefixes="xsi xs n1 fn">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<n1:MobilStandard>
<xsl:apply-templates select="n1:MobilStandard/Trans"/>
</n1:MobilStandard>
</xsl:template>
<xsl:template match="Trans">
<Trans>
<Item>
<ID>
<xsl:value-of select="Docket"/>
</ID>
<Product>
<xsl:value-of select="Fee"/>
</Product>
<Amount>
<xsl:value-of select="Amount"/>
</Amount>
</Item>
<xsl:apply-templates select="following-sibling::TransItem[preceding-sibling::Trans[1]=current()]"/>
</Trans>
</xsl:template>
<xsl:template match="TransItem">
<Item>
<ID>
<xsl:value-of select="preceding-sibling::Trans[1]/Docket"/>
</ID>
<Product>
<xsl:value-of select="Product"/>
</Product>
<Amount>
<xsl:value-of select="Amount"/>
</Amount>
</Item>
</xsl:template>
</xsl:stylesheet>

Alberto

Posttop
Simon CowleySubject: Grouping without For-Each
Author: Simon Cowley
Date: 22 Oct 2007 06:55 PM
Alberto

Thanks for your help.

This has solved my issue.

Many thanks

Simon

   
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.