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 February 21st, 2006, 08:36 PM
Registered User
 
Join Date: Feb 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Need help in writing an xslt

Hi,
This is my source xml
<Forecast>
    <Product>
        <Id>1</Id>
        <Schedule>
            <ScheduleDetail>
                <StartDate>1</StartDate>
                <EndDate>1</EndDate>
                <Quantity>1</Quantity>
            </ScheduleDetail>
            <ScheduleDetail>
                <StartDate>2</StartDate>
                <EndDate>2</EndDate>
                <Quantity>2</Quantity>
            </ScheduleDetail>
        </Schedule>
    </Product>
    <Product>
        <Id>2</Id>
        <Schedule>
            <ScheduleDetail>
                <StartDate>3</StartDate>
                <EndDate>3</EndDate>
                <Quantity>3</Quantity>
            </ScheduleDetail>
            <ScheduleDetail>
                <StartDate>4</StartDate>
                <EndDate>4</EndDate>
                <Quantity>4</Quantity>
            </ScheduleDetail>
        </Schedule>
    </Product>


And this is the target xml
<Items>
    <Data>
        <Product>1</Product>
        <Startdate>1</StartDate>
        </EndDate>1</EndDate>
        <Quantity>1</Quantity>
    <Data>
    <Data>
        <Product>1</Product>
        <Startdate>2</StartDate>
        </EndDate>2</EndDate>
        <Quantity>2</Quantity>
    <Data>
    <Data>
        <Product>2</Product>
        <Startdate3></StartDate>
        </EndDate>3</EndDate>
        <Quantity>3</Quantity>
    <Data>
    <Data>
        <Product>2</Product>
        <Startdate>4</StartDate>
        </EndDate>4</EndDate>
        <Quantity>4</Quantity>
    <Data>
</Items>
Any ideas how I can do this?

Thanks,
Subir

 
Old February 22nd, 2006, 06:45 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You're producing one Data element for each ScheduleDetail element in the input, so you will want something like

<xsl:template match="ScheduleDetail">
<Data>
  ...
</Data>
</xsl:template>

The StartDate, EndDate, and Quantity elements can be copied over using <xsl:copy-of select="*"/>, and the Product can be added as

<Product><xsl:value-of select="../preceding-sibling::Id"/></Product>



Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
General XSLT Questions in the XSLT Forum jminatel BOOK: XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition ISBN: 978-0-470-19274-0 0 March 31st, 2008 07:50 PM
Writing A Macro Venusbj VB How-To 2 January 30th, 2008 01:10 AM
Can XSLT read DTD/schema and Generate XSLT.. ROCXY XSLT 1 November 6th, 2006 09:39 AM
dynamic xslt -> xslt creation namespace problem jkmyoung XSLT 2 July 15th, 2006 12:42 AM





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