Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
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
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old May 28th, 2005, 02:09 AM
Registered User
 
Join Date: May 2005
Location: , , Sweden.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to supafly
Default Elements w same name and their attributes

Hi!
Trying to transform a document with a lot of elements with same name, and want to extract all their attributes.

I have this:
<g>
  <rect id="1" x="100" y="100" ... />
  <rect id="2" x="101" y="101" ... />
  ...
</g>

And would like something like this:
<PARENT>
   <CHILD>
     <ID>1</ID>
     <X>100</X>
     <Y>100</Y>
     ...
   </CHILD>
   <CHILD>
     ..
   </CHILD>
   ...
</PARENT>


Having really hard time to figure out how to write xsl stylesheet to do this transform, hint plz!!!???
Reply With Quote
  #2 (permalink)  
Old May 30th, 2005, 06:34 AM
Authorized User
 
Join Date: Apr 2005
Location: Chennai, Tamil Nazdu, India.
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
    &lt;PARENT&gt;
         <xsl:apply-templates/>
    <br/>&lt;/PARENT&gt;

</xsl:template>

<xsl:template match="g">
    <xsl:for-each select="rect">
    <pre>
    &lt;CHILD&gt;<br/>
                &lt;ID&gt;<xsl:value-of select="@id"/>&lt;/ID&gt;
                &lt;X&gt;<xsl:value-of select="@x"/>&lt;/X&gt;
                &lt;Y&gt;<xsl:value-of select="@y"/>&lt;/Y&gt;

    &lt;/CHILD&gt;
    </pre><br/>

      </xsl:for-each>


</xsl:template>


</xsl:stylesheet>


Reply With Quote
Reply


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
Elements and attributes Morrislgn XSLT 1 June 20th, 2005 11:13 AM
Help:Recursive Function - attributes into elements spencer.clark XSLT 1 June 10th, 2005 07:56 AM



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


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