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 April 12th, 2006, 07:34 AM
Registered User
 
Join Date: Apr 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default NEWBIE: Copy and Rename

I'm trying to do a simple copy and rename:

Assume the following XML:
<food name="joe">
    <pizza name="Large">
    <topping name="mushroom"/>
    </pizza>
</food>

I want to :
1) make a copy of the pizza node
2) change the name of copied version to "Big"
3) change the name (in the copied version) of "mushroom" to "onion"

so the output would be
<food name="joe">
    <pizza name="Large">
    <topping name="mushroom"/>
    </pizza>
    <pizza name="Big">
    <topping name="onion"/>
    </pizza>
</food>

I tried using a template match with a copy, but I got my #1 and #2 but I couldn't reference the newly created pizza node using XPath.

Any help would really be appreciated.
Thanks!

 
Old April 12th, 2006, 09:21 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

It would be useful to show your code so we can see where you went wrong.

Referencing a newly created node using XPath can't be done in XSLT 1.0 except with the xx:node-set() extension function = but it's not something you need to do to solve this problem

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old April 12th, 2006, 10:16 AM
Registered User
 
Join Date: Apr 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Here's a portion of my XSL: Thanks for looking!


<xsl:template match="node() | @*">
    <xsl:copy>
        <xsl:apply-templates select="node() | @*"/>
    </xsl:copy>
  </xsl:template>


<xsl:template match="//food/pizza[@name='Large']">
    <xsl:copy>
        <xsl:apply-templates select="node() | @*"/>
    </xsl:copy>
    <xsl:copy>
        <xsl:attribute name="name">Big</xsl:attribute>
        <xsl:copy-of select="node()"/>
    </xsl:copy>
  </xsl:template>


<xsl:template match="//food/pizza[@name='Big']">
    <xsl:element name="topping">
         <xsl:attribute name="name">onion</xsl:attribute>
    </xsl:element>
  </xsl:template>



 
Old April 12th, 2006, 01:00 PM
Registered User
 
Join Date: Apr 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I looked at node-set() but I'm sure there's an easy way to do this. Suggestions?






Similar Threads
Thread Thread Starter Forum Replies Last Post
copy an access database and then rename it . yeetesh VB Databases Basics 4 December 27th, 2007 09:26 AM
Copy worksheet to another workbook and rename it Probleminfinity Excel VBA 1 August 19th, 2007 11:38 PM
copy and rename red_fiesta Classic ASP Professional 1 November 8th, 2006 11:00 AM
Rename node name venutm XML 0 March 9th, 2006 03:36 PM
copy an access database and then rename it . yeetesh Beginning VB 6 1 January 7th, 2005 04:40 PM





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