Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register | 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 Display Modes
  #1 (permalink)  
Old June 20th, 2005, 09:32 AM
Authorized User
Join Date: Jan 2004
Location: Belfast, , United Kingdom.
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
Default Elements and attributes

Hi Folks,

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, I want to the <CarPrice> node to remain as an attribute. I know that you can convert elements to attributes etc, but is there an easier way than converting all attributes to elements and then selecting the one element you want to turn back into in an attribute.

This is the style sheet I am using at the moment:

<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( )"/>

Sorta new to this XSLT stuff, so all help is appreciated.



Reply With Quote
  #2 (permalink)  
Old June 20th, 2005, 11:13 AM
Authorized User
Points: 251, Level: 5
Points: 251, Level: 5 Points: 251, Level: 5 Points: 251, Level: 5
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Jun 2003
Location: , , Canada.
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to rushman


I just dropped the namespaces from your source to make it simple (I didn't look for them ...)

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
            <xsl:apply-templates select="//row"></xsl:apply-templates>
    <xsl:template match="row">
            <xsl:attribute name="CarPrice">
                <xsl:value-of select="@CarPrice"/>
            <xsl:for-each select="@*[name() != 'CarPrice']">
                <xsl:element name="{name()}">
                    <xsl:value-of select="."/>

Dijkstra's law on Programming and Inertia:

If you don't know what your program is supposed to do, don't try to write it.
Reply With Quote

Thread Tools
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
remove empty elements but not ones with attributes dupdup XSLT 1 March 3rd, 2007 06:02 PM
how to control optional elements and attributes NEO1976 XSLT 5 September 4th, 2006 02:58 AM
sequenced elements to attributes zkent XSLT 0 April 19th, 2006 08:50 AM
Help:Recursive Function - attributes into elements spencer.clark XSLT 1 June 10th, 2005 07:56 AM
Elements w same name and their attributes supafly XSLT 1 May 30th, 2005 06:34 AM

All times are GMT -4. The time now is 02:09 AM.

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