Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
| 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
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 31st, 2005, 05:26 AM
Authorized User
Join Date: Jan 2004
Location: Belfast, , United Kingdom.
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem Renaming an Element

Hi Folks,

I have a problem when I try to rename an element, that all the child nodes of the element are wiped out.

I am trying to convert an ADODB.RecordSet to a more readable form:

    <z:row CarVidNo="33445566" CarRegNo="345rtgy" CarMake="Renault" CarModel="Clio" CarColour="Blue" CarEngine="1.2" CarPrice="5000"/>
    <z:row CarVidNo="55667788" CarRegNo="SXI 6002" CarMake="Vauxhall" CarModel="Corsa" CarColour="White" CarEngine="1.1" CarPrice="1000"/>

Like So:


However, when I try to convert <z:row> to another name, say <cars> I get this:


Here is the stylesheet I am using:

<xsl:import href="copy.xslt"/>

    <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" />

      <xsl:template match="*[z:row]">



        <xsl:template match="s:Schema">
                <xsl:for-each select="z:row">
                    <xsl:apply-templates />

        <xsl:template match="z:row/@*">
          <xsl:element name="{name( )}">
                <xsl:value-of select="." />

        <xsl:template match="z:row">
          <xsl:element name="Cars">
                <xsl:apply-templates select="z:row"/>

And here is the copy stylesheet:

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

I am at a loss with this, been looking around the net and in some books, but as far as i can see, this should work.

Thanks for your help!


Reply With Quote
  #2 (permalink)  
Old May 31st, 2005, 05:59 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts

<xsl:template match="z:row">
          <xsl:element name="Cars">
                <xsl:apply-templates select="z:row"/>

A z:row element does not have any children called z:row, so this apply-templates will select nothing.

You want <apply-templates select="@*"/>.

Michael Kay
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
  #3 (permalink)  
Old May 31st, 2005, 06:18 AM
Authorized User
Join Date: Jan 2004
Location: Belfast, , United Kingdom.
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts


Oh so simple when you know how!! :o)

Thanks for your help, it is much appreicated!


Reply With Quote

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
Problem adding element to the previous element dani1 XSLT 5 September 10th, 2008 01:38 AM
Problem in adding the new element into the XML fil Somesh C# 3 February 6th, 2007 06:41 AM
Problem -- Empty element check ! back2grave XSLT 2 July 10th, 2006 04:58 PM
Schema Complex element with restriction problem ravik@olemiss.edu XML 1 June 27th, 2006 11:45 AM
adding of element and assigning to one element sushovandatta XSLT 2 November 16th, 2004 07:04 PM

All times are GMT -4. The time now is 11:50 AM.

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