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 28th, 2005, 02:09 AM
Registered User
 
Join Date: May 2005
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!!!???
 
Old May 30th, 2005, 06:34 AM
Authorized User
 
Join Date: Apr 2005
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>







Similar Threads
Thread Thread Starter Forum Replies Last Post
remove empty elements but not ones with attributes dupdup XSLT 1 March 3rd, 2007 07: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





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