Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
| Search | Today's Posts | Mark Forums Read
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
  #1 (permalink)  
Old November 9th, 2008, 06:07 AM
Registered User
 
Join Date: Nov 2008
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Need Help in XSL Transformation -Urgent

I have the following requirement in XSL:

ie., Lets say for eg: I have the source and destination as follows
Source :
--------
<ForwardOrder>
 <FulfillLines>

  <Fline>
   <FlineId>100</FlineId>
   <Status>success</Status>
  </Fline>

  <Fline>
   <FlineId>200</FlineId>
   <Status>success</Status>
  </Fline>

  <Fline>
   <FlineId>300</FlineId>
   <Status>success</Status>
  </Fline>

  <Fline>
  <FlineId>100</FlineId>
  <Status>success</Status>
  </Fline>

  <Fline>
  <FlineId>300</FlineId>
  <Status>success</Status>
  </Fline>

 </FulfillLines>
</ForwardOrder>


Target should be :
-----------------
<ReturnOrder>
 <FulfillLines>

  <Fline>
   <FlineId>100</FlineId>
   <Status>success</Status>
  </Fline>

  <Fline>
   <FlineId>200</FlineId>
   <Status>success</Status>
  </Fline>

  <Fline>
   <FlineId>300</FlineId>
   <Status>success</Status>
  </Fline>

  <Fline>
  <FlineId>400</FlineId>
  <Status>success</Status>
  </Fline>

 </FulfillLines>
</ReturnOrder>


Explanation :
Based on the FlineId , if there is any repeating Fline in the source that should be eliminated in the target.
***Please respond with whatever relevant suggestions u have as this is urgent**

Thanks and Regards,
Sridhar.


  #2 (permalink)  
Old November 9th, 2008, 06:06 PM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Please use a title that describes your problem. Everyone posting to this list needs help with XSL transformation, and most people would like the answer yesterday (though most have the good sense not to say so, since it tends to discourage people from answering - that's because people who are in too much of a hurry often come back immediately with supplementary questions rather than taking time to study the answers).

In fact your question is a standard grouping problem, and if you search for "XSLT Grouping" in the index of your favourite XSLT textbook or on the web then you will find good explanations of how to solve such problems in XSLT 1.0 or XSLT 2.0 - the 2.0 solutions are much easier.

Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer's Reference
  #3 (permalink)  
Old November 11th, 2008, 04:03 AM
Friend of Wrox
Points: 1,306, Level: 14
Points: 1,306, Level: 14 Points: 1,306, Level: 14 Points: 1,306, Level: 14
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2008
Location: Pondicherry, India
Posts: 291
Thanks: 9
Thanked 29 Times in 29 Posts
Default

Try this:

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="ForwardOrder">
        <ReturnOrder>
        <xsl:apply-templates/>
        </ReturnOrder>
    </xsl:template>

    <xsl:template match="FulfillLines">
        <FulfillLines>
            <xsl:for-each-group select="Fline" group-by="FlineId">
                <xsl:copy-of select=".[1]"></xsl:copy-of>
            </xsl:for-each-group>
            <xsl:apply-templates/>
        </FulfillLines>
    </xsl:template>

    <xsl:template match="FlineId"/>
    <xsl:template match="Status"/>

    </xsl:stylesheet>

It may any forum, ask your questions with title describing only your problem, as Mike had said.

------
Rummy


Similar Threads
Thread Thread Starter Forum Replies Last Post
xsl transformation ... rajesh_css XSLT 5 September 30th, 2008 12:37 AM
XSL-Transformation atulshin XSLT 4 September 15th, 2008 06:37 AM
XSL transformation problem kawal.singh XSLT 2 December 5th, 2006 05:58 AM
Transformation of XSL text sg1973 XSLT 5 August 9th, 2006 03:47 PM
XSL transformation Thodoris XML 0 May 20th, 2004 08:33 AM





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