Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 26th, 2007, 05:48 AM
Registered User
 
Join Date: Mar 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default xslt recursion (need help )

can someone please help me , i have a source xml file which needs to be transformed into another xml document with a deeper Hierarchy based on the value of element (E3) a new category (scheme ) is created and the table data needs to be copied in as children in
the result document is i have copied a sample source/result below
many thanks :

source:
<NewDataSet>
  <Table>
    <F1>1315578</F1>
    <E1>21</E1>
    <E3>2007-01-05T00:00:00+00:00</E3>
    <E4>P</E4>
    <E5>4597</E5>
    <E6>RfD</E6>
  </Table>

  <Table>
    <F1>6003290</F1>
    <E1>101</E1>
    <E3>2007-01-05T00:00:00+00:00</E3>
    <E4>P</E4>
    <E5>4596</E5>
    <E6>RfD</E6>
  </Table>
  <Table>
    <F1>6003674</F1>
    <E1>101</E1>
    <E3>2007-01-05T00:00:00+00:00</E3>
    <E4>P</E4>
    <E5>4605</E5>
    <E6>Taxicommute</E6>
  </Table>

  <Table>
    <F1>6003893</F1>
    <E1>103</E1>
    <E3>2007-01-05T00:00:00+00:00</E3>
    <E4>P</E4>
    <E5>4599</E5>
    <E6>RfD</E6>
  </Table>
  <Table>
    <F1>6003893</F1>
    <E1>202</E1>
    <E3>2007-01-05T00:00:00+00:00</E3>
    <E4>P</E4>
    <E5>4599</E5>
    <E6>RfD</E6>
  </Table>

</NewDataSet>

and a sample of the result should look like :

<?xml version="1.0" encoding="UTF-8" ?>
- <DisbursementsExtract ExtractDate="31/08/2006">
- <HEADER>
  <TRANSACTIONS />
  </HEADER>
- <SCHEME>
- <SCHEME_REFERENCE>
  <E1>101</E1>
  </SCHEME_REFERENCE>
- <Table>
  <E3>Junior</E3>
  <E4>RM</E4>
  <E5>MRS</E5>
  <E6>A130168</E6>
  </Table>
- <Table>
  <E3>Sorter</E3>
  <E4>A</E4>
  <E5>MR</E5>
  <E6>A133090</E6>
  </Table>
  </SCHEME>
- <SCHEME>
- <SCHEME_REFERENCE>
  <E1>21</E1>
  </SCHEME_REFERENCE>
- <Table>
  <E3>Pearson</E3>
  <E4>PA</E4>
  <E5>MS</E5>
  <E6>A069329</E6>
  </Table>
  </SCHEME>
  </DisbursementsExtract>



 
Old March 26th, 2007, 06:28 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

This isn't a specification that anyone can work from. There is no obvious relationship between your input and your output. Where do the names Junior, Sorter, and Pearson come from, for example?

It's also useful to tell us how you tried to solve this problem and where you got stuck. If I'm going to help you solve it, I want to know which parts of the problem you are capable of tackling on your own and which parts you need help with.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old March 26th, 2007, 07:46 AM
Registered User
 
Join Date: Mar 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

My apologies my result should look like the document below :
i have done the formation of one scheme but i get stuck when i need to get the element value and check it against the last E3 value to decide whether it goes in the current scheme or i need to create a new scheme.

my transformation creates one scheme and put all the tables under that scheme ,i want it to create a new scheme for each group of tables with the same value in Element E3.

 <?xml version="1.0" encoding="UTF-8" ?>
- <DisbursementsExtract ExtractDate="31/08/2006">
- <HEADER>
  <TRANSACTIONS />
  </HEADER>
- <SCHEME>
- <SCHEME_REFERENCE>
  <E1>101</E1>
  </SCHEME_REFERENCE>
- <Table>
  <E3>2007-01-05T00:00:00+00:00</E3>
  <E4>P</E4>
  <E5>4597</E5>
  <E6>RfD</E6>
  </Table>
- <Table>
  <E3>2007-01-05T00:00:00+00:00</E3>
  <E4>P</E4>
  <E5>4596</E5>
  <E6>RfD</E6>
  </Table>
  </SCHEME>
- <SCHEME>
- <SCHEME_REFERENCE>
  <E1>21</E1>
  </SCHEME_REFERENCE>
- <Table>
  <E3>2007-01-05T00:00:00+00:00</E3>
  <E4>P</E4>
  <E5>4605</E5>
  <E6>RfD</E6>
  </Table>
  </SCHEME>
  </DisbursementsExtract



 
Old March 26th, 2007, 08:19 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

>i get stuck when i need to get the element value and check it against the last E3 value to decide whether it goes in the current scheme or i need to create a new scheme

OK, thanks that makes it clear: you are doing grouping. Grouping is much easier in XSLT 2.0 using the xsl:for-each-group element. If you're stuck with XSLT 1.0, look at http://www.jenitennison.com/xslt/grouping for a range of techniques that can be applied.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old March 26th, 2007, 10:59 AM
Registered User
 
Join Date: Mar 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks MHKay i have been able to to do the first level of recursion using using the informaton from Jenitennison's website ...many thanks for your quick reply ..you've been a great help






Similar Threads
Thread Thread Starter Forum Replies Last Post
Recursion problem dani1 XSLT 5 November 26th, 2008 10:05 AM
Recursion lincsimp XSLT 1 August 16th, 2005 04:26 PM
recursion yui0329 C# 6 April 28th, 2005 09:36 AM
Recursion shan9 JSP Basics 0 November 17th, 2004 09:29 PM
recursion nulogix PHP How-To 1 June 28th, 2004 03:58 PM





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