Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
Register | FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 29th, 2008, 02:23 AM
Authorized User
 
Join Date: Sep 2008
Location: , , .
Posts: 26
Thanks: 2
Thanked 0 Times in 0 Posts
Default Convert Flat structure to Nested

Hi! I need do convert a flat structure to nested one.
I know how to do this using the condition, but now I don't have any common "keys" between the items.
I need to save the original order of the items.

[u]Source structure:</u>

<root>
    <Invoice>
        <InvType>0</InvType>
        <InvNum>111</InvNum>
    </Invoice>
    <Delivery>
        <DeliveryType>1</DeliveryType>
        <DeliveryNum>111</DeliveryNum>
        <Amount>100.00</Amount>
    </Delivery>
    <Delivery>
        <DeliveryType>1</DeliveryType>
        <DeliveryNum>333</DeliveryNum>
        <Amount>200.00</Amount>
    </Delivery>
    <Invoice>
        <InvType>0</InvType>
        <DeliveryNum>222</DeliveryNum>
    </Invoice>
    <Delivery>
        <DeliveryType>1</DeliveryType>
        <DeliveryNum>222</DeliveryNum>
        <Amount>300.00</Amount>
    </Delivery>
</root>

[u]Target:</u>

<root>
    <Invoice>
        <InvType>0</InvType>
        <InvNum>111</InvNum>
        <Delivery>
             <DeliveryType>1</DeliveryType>
             <DeliveryNum>111</DeliveryNum>
             <Amount>100.00</Amount>
        </Delivery>
        <Delivery>
             <DeliveryType>1</DeliveryType>
             <DeliveryNum>333</DeliveryNum>
             <Amount>200.00</Amount>
        </Delivery>
    </Invoice>

    <Invoice>
        <InvType>0</InvType>
        <DeliveryNum>222</DeliveryNum>
        <Delivery>
                <DeliveryType>1</DeliveryType>
                <DeliveryNum>222</DeliveryNum>
                <Amount>300.00</Amount>
        </Delivery>
    </Invoice>
</root>

[u]Here is my code:</u>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
        <root>
            <xsl:for-each select="root/Invoice">
                <Invoice>
                    <InvType>
                        <xsl:value-of select="InvType"/>
                    </InvType>
                    <InvNum>
                        <xsl:value-of select="InvNum"/>
                    </InvNum>
********Here I can insert a condition, but I don't have any :(*******
For example: <xsl:for-each select="../Delivery[DeliveryType=../Invoice/InvType]">
************************************************** *****************
                        <Delivery>
                            <DeliveryType>
                                <xsl:value-of select="DeliveryType"/>
                            </DeliveryType>
                            <DeliveryNum>
                                <xsl:value-of select="DeliveryNum"/>
                            </DeliveryNum>
                            <Amount>
                                <xsl:value-of select="Amount"/>
                            </Amount>
                        </Delivery>
                    </xsl:for-each>
                </Invoice>
            </xsl:for-each>
        </root>
    </xsl:template>
</xsl:stylesheet>

How can solve the problem?
Reply With Quote
  #2 (permalink)  
Old October 29th, 2008, 02:36 AM
Authorized User
 
Join Date: Sep 2008
Location: , , Singapore.
Posts: 87
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Hi,

<Invoice>
        <InvType>0</InvType>
        <InvNum>111</InvNum>
    </Invoice>
    <Delivery>
        <DeliveryType>1</DeliveryType>
        <DeliveryNum>111</DeliveryNum>
        <Amount>100.00</Amount>
    </Delivery>
    <Delivery>
        <DeliveryType>1</DeliveryType>
        <DeliveryNum>333</DeliveryNum>
        <Amount>200.00</Amount>
    </Delivery>
    <Invoice>
        <InvType>0</InvType>
        <DeliveryNum>222</DeliveryNum>
    </Invoice>
    <Delivery>
        <DeliveryType>1</DeliveryType>
        <DeliveryNum>222</DeliveryNum>
        <Amount>300.00</Amount>
    </Delivery>

is this the way u r expecting

<xsl:template match="/">
        <xsl:copy-of select="./node()" />
    </xsl:template>

will give the result as i mentioned.here the invoice tag is ending before the delivery tag.


Raj
Reply With Quote
  #3 (permalink)  
Old October 29th, 2008, 02:51 AM
Authorized User
 
Join Date: Sep 2008
Location: , , .
Posts: 26
Thanks: 2
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by rajesh_css
 Hi,

<Invoice>
        <InvType>0</InvType>
        <InvNum>111</InvNum>
    </Invoice>
    <Delivery>
        <DeliveryType>1</DeliveryType>
        <DeliveryNum>111</DeliveryNum>
        <Amount>100.00</Amount>
    </Delivery>
    <Delivery>
        <DeliveryType>1</DeliveryType>
        <DeliveryNum>333</DeliveryNum>
        <Amount>200.00</Amount>
    </Delivery>
    <Invoice>
        <InvType>0</InvType>
        <DeliveryNum>222</DeliveryNum>
    </Invoice>
    <Delivery>
        <DeliveryType>1</DeliveryType>
        <DeliveryNum>222</DeliveryNum>
        <Amount>300.00</Amount>
    </Delivery>

is this the way u r expecting

<xsl:template match="/">
        <xsl:copy-of select="./node()" />
    </xsl:template>

will give the result as i mentioned.here the invoice tag is ending before the delivery tag.
Raj
Hi Raj!

This is the source flat structure:

<Invoice>
        <InvType>0</InvType>
        <InvNum>111</InvNum>
    </Invoice>
    <Delivery>
        <DeliveryType>1</DeliveryType>
        <DeliveryNum>111</DeliveryNum>
        <Amount>100.00</Amount>
    </Delivery>
    <Delivery>
        <DeliveryType>1</DeliveryType>
        <DeliveryNum>333</DeliveryNum>
        <Amount>200.00</Amount>
    </Delivery>
    <Invoice>
        <InvType>0</InvType>
        <DeliveryNum>222</DeliveryNum>
    </Invoice>
    <Delivery>
        <DeliveryType>1</DeliveryType>
        <DeliveryNum>222</DeliveryNum>
        <Amount>300.00</Amount>
    </Delivery>

I expecting to the nested structure, like that:

<root>
    <Invoice>
        <InvType>0</InvType>
        <InvNum>111</InvNum>
        <Delivery>
             <DeliveryType>1</DeliveryType>
             <DeliveryNum>111</DeliveryNum>
             <Amount>100.00</Amount>
        </Delivery>
        <Delivery>
             <DeliveryType>1</DeliveryType>
             <DeliveryNum>333</DeliveryNum>
             <Amount>200.00</Amount>
        </Delivery>
    </Invoice>
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Flat XML to nested IgorK XSLT 10 November 24th, 2008 09:56 AM
Convert nested XML to flat one dani1 XSLT 15 October 21st, 2008 02:20 AM
Flat DB structure into XML Hierarchy DaveQuested XSLT 1 January 29th, 2007 10:25 AM
Flat XML structure to a tree by XSLT Borg0011 XSLT 2 July 9th, 2006 08:58 AM
mapping repeating xml structure to flat csv f vasmallela Biztalk 0 May 29th, 2005 11:53 PM



All times are GMT -4. The time now is 06:14 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.