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: XSLT grouping
Author: Simon Cowley
Date: 21 Aug 2007 08:22 PM
Hi all

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

Can anyone suggest a solution?

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
Tony LavinioSubject: XSLT grouping
Author: Tony Lavinio
Date: 22 Aug 2007 02:03 PM
Type "xslt grouping" into Google and follow the first hit into "Jeni's XSLT Pages: Grouping" at http://www.jenitennison.com/xslt/grouping/ which has your answer.

Posttop
Simon CowleySubject: XSLT grouping
Author: Simon Cowley
Date: 24 Sep 2007 09:03 PM
Thanks Tony

I am still struggling to find the solution in the documentation provided?

Do you or anyone else have any other pointers?

Cheers

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.