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
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext 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

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
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.