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 December 19th, 2006, 06:43 PM
Authorized User
 
Join Date: Oct 2006
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Default Copy element into complexType in XSLT

I have this XML:

<Group>
  <SubGroupA>
    <Sam>Girl</Sam>
    <Bob>Boy</Bob>
  <SubGroupA>
  <Tim>Boy</Tim>
  <SubGroupB>
     <Mike>Boy</Mike>
     <Robin>Girl</Robin>
  <SubGroupB>
</Group>

I like to insert <Tim> inside <SubTeamB> in my new XML. <Tim> has to be between <Mike> and <Robin>. This is what I like in the final result. Please note that "Group" is changed to "Team".

<Team>
  <SubTeamA>
    <Sam>Girl</Sam>
    <Bob>Boy</Bob>
  <SubTeamA>
  <SubTeamB>
     <Mike>Boy</Mike>
     <Tim>Boy</Tim>
     <Robin>Girl</Robin>
  <SubTeamB>
</Team>

My piece of XSLT is the following:
<xsl:template match="SubGroupB">
    <SubTeamB>
        <xsl:copy-of select="Mike">
        <Tim/> <---- Issue is here. Tim has no value.
        <xsl:copy-of select="Robin">
    </SubTeamB>
</xsl:template>

How do I get <Tim> inside <SubTeamB> when my <SubGroupB> template has no access to <Tim>? Please help.
 
Old December 20th, 2006, 04:24 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

I don't follow this at all, where does <Tim> come from?
If it's hard-coded just change what you have to:
Code:
<xsl:template match="SubGroupB">
    <SubTeamB>
        <xsl:copy-of select="Mike">
        <Tim>Boy</Tim> 
        <xsl:copy-of select="Robin">
    </SubTeamB>
</xsl:template>
Otherwise I suggest you provide a bit more detail about your input, current XSLT and desired output.

--

Joe (Microsoft MVP - XML)
 
Old December 20th, 2006, 09:00 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

<xsl:copy-of select="../Tim"/>

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old December 20th, 2006, 09:09 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

My eyesight's going, I completely missed the <Tim> element between the SubGroups :)

--

Joe (Microsoft MVP - XML)





Similar Threads
Thread Thread Starter Forum Replies Last Post
XSLT - fetching element value without getting the samridhis XSLT 4 August 11th, 2008 03:30 AM
Element value type in XSLT 1.0 NEO1976 XSLT 9 February 13th, 2007 11:11 AM
Write XML element into textbox with XSLT tcstom XSLT 4 July 5th, 2006 04:08 AM
Copy source-element to output tree der_bAUer XSLT 2 June 9th, 2006 08:17 AM
xslt copy-of ppeou XSLT 5 August 24th, 2003 07:09 AM





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