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 May 31st, 2005, 05:26 AM
Authorized User
 
Join Date: Jan 2004
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:

<rs:data>
    <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"/>
</rs:data>

Like So:

<z:row>
    <CarVidNo>33445566</CarVidNo>
    <CarRegNo>345rtgy</CarRegNo>
    <CarMake>Renault</CarMake>
    <CarModel>Clio</CarModel>
    <CarColour>Blue</CarColour>
    <CarEngine>1.2</CarEngine>
    <CarPrice>5000</CarPrice>
</z:row>

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

<Cars/>

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:apply-templates/>

      </xsl:template>


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


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


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


And here is the copy stylesheet:


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


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!

Morris

 
Old May 31st, 2005, 05:59 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

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

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
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old May 31st, 2005, 06:18 AM
Authorized User
 
Join Date: Jan 2004
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hey!!

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

Thanks for your help, it is much appreicated!

Morris






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 [email protected] 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





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