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 October 20th, 2008, 10:36 AM
Authorized User
 
Join Date: Sep 2008
Posts: 26
Thanks: 2
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by mhkay
 Please don't think in terms of "closing the tag". You're writing a tree of nodes, not a sequence of start and end tags.
OK, I'll do my best.

Quote:
quote:Originally posted by mhkay
The reason that there's a text node after the <Order> element is that you wrote it when you did

        <Order>
            <xsl:copy-of select="OrderNum"/>
            <xsl:copy-of select="OrderData1"/>
            <xsl:copy-of select="OrderData2"/>
            <xsl:copy-of select="OrderData3"/>
        </Order>
        <xsl:apply-templates/>

If you don't want it, why are you doing the apply-templates?

Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer's Reference
But if I am not doing "apply-templates", I lost the next elements in tree.

For example if I remove "apply-templates" in "Orders", I'll have no elements "Line".
 
Old October 20th, 2008, 10:42 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Then use the xsl:apply-templates but add a template
Code:
<xsl:template match="text()"/>
to ensure that text nodes are not copied.

--
  Martin Honnen
  Microsoft MVP - XML
 
Old October 20th, 2008, 11:05 AM
Authorized User
 
Join Date: Sep 2008
Posts: 26
Thanks: 2
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by Martin Honnen
 Then use the xsl:apply-templates but add a template
Code:
<xsl:template match="text()"/>
to ensure that text nodes are not copied.

--
Martin Honnen
Microsoft MVP - XML
I am sorry, I didn't understand how I can do that. May be you can give some example?
 
Old October 20th, 2008, 11:15 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

I gave you the code already, add the template
Code:
<xsl:template match="text()"/>
to your stylesheet.

--
  Martin Honnen
  Microsoft MVP - XML
 
Old October 20th, 2008, 11:15 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 291
Thanks: 9
Thanked 29 Times in 29 Posts
Default

Try this:

 <xsl:template match="/">
        <root>
            <xsl:apply-templates/>
        </root>
    </xsl:template>

    <xsl:template match="Line">
        <xsl:copy-of select="."/>
    </xsl:template>

    <xsl:template match="Order">
        <Order>
            <xsl:copy-of select="OrderNum"/>
            <xsl:copy-of select="OrderData1"/>
            <xsl:copy-of select="OrderData2"/>
            <xsl:copy-of select="OrderData3"/>
        </Order>
        <xsl:apply-templates select="Line"/>
    </xsl:template>

    <xsl:template match="Header">
        <Header>
            <xsl:copy-of select="Hdr"/>
            <xsl:copy-of select="Data1"/>
            <xsl:copy-of select="Data2"/>
            <xsl:copy-of select="Data3"/>
        </Header>
        <xsl:apply-templates select="Order"/>
    </xsl:template>

Rummy
 
Old October 21st, 2008, 02:20 AM
Authorized User
 
Join Date: Sep 2008
Posts: 26
Thanks: 2
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by mrame
 Try this:

<xsl:template match="/">
        <root>
            <xsl:apply-templates/>
        </root>
    </xsl:template>

    <xsl:template match="Line">
        <xsl:copy-of select="."/>
    </xsl:template>

    <xsl:template match="Order">
        <Order>
            <xsl:copy-of select="OrderNum"/>
            <xsl:copy-of select="OrderData1"/>
            <xsl:copy-of select="OrderData2"/>
            <xsl:copy-of select="OrderData3"/>
        </Order>
        <xsl:apply-templates select="Line"/>
    </xsl:template>

    <xsl:template match="Header">
        <Header>
            <xsl:copy-of select="Hdr"/>
            <xsl:copy-of select="Data1"/>
            <xsl:copy-of select="Data2"/>
            <xsl:copy-of select="Data3"/>
        </Header>
        <xsl:apply-templates select="Order"/>
    </xsl:template>

Rummy
Thank you, Rummy. That's it! :)

Now I have understood Martin Honnen's advise.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Flat XML to nested IgorK XSLT 10 November 24th, 2008 09:56 AM
Convert Flat structure to Nested dani1 XSLT 2 October 29th, 2008 02:51 AM
Help in making a FLAT xml to a structured xml shlomi XSLT 0 July 19th, 2007 07:58 AM
flat XML to hierarchical XML eduijs XSLT 1 April 28th, 2006 05:43 AM
translating a flat xml to a hierarchical xml stevea XSLT 4 June 13th, 2005 05:55 PM





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