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 June 10th, 2005, 08:28 AM
Authorized User
 
Join Date: Jun 2005
Location: , , .
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Default Help:Recursive Function - attributes into elements

Hi, I am fairly new at XSLT. I was wondering if anyone knew how to convert attributes into a child element of the original element.
Here is an example of code that I have:
<w:sectPr>
 <w:pgSz w:w="12240" w:h="15840"/>
 <w:pgMar w:top="1440" w:right="1800" w:bottom="1440" w:left="1800" w:header="720" w:footer="720" w:gutter="0"/>
 <w:cols w:space="720"/>
 <w:docGrid w:line-pitch="360"/>
</w:sectPr>

And I would like to have it transformed into.


<w:sectPr>
 <w:pgSz>
  <w:w>12240</w:w>
  <w:h>15840</w:h>
 </w:pgSz>
 <w:pgMar>
  <w:top>1440</w:top>
  <w:right>1800</w:right>
  <w:bottom>1440</w:bottom>
  <w:left>1800</w:left>
  <w:header>720</w:header>
  <w:footer>720</w:footer>
  <w:gutter>0</w:gutter>
 </w:pgMar>
 <w:cols>
  <w:space>720</w:space>
 </w:cols>
 <w:docGrid>
  <w:line-pitch>360</w:line-pitch>
 </w:docGrid>
</w:sectPr>
 Also, please note that I need for this recursive function to start at the root node. (w:wordDocument). And thank you in advance to anyone that can provide me with any helpful advice!

Reply With Quote
  #2 (permalink)  
Old June 10th, 2005, 08:56 AM
mhkay's Avatar
Wrox Author
Points: 18,280, Level: 58
Points: 18,280, Level: 58 Points: 18,280, Level: 58 Points: 18,280, Level: 58
Activity: 33%
Activity: 33% Activity: 33% Activity: 33%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,934
Thanks: 0
Thanked 282 Times in 277 Posts
Default

<xsl:template match="*">
  <xsl:for-each select="@*">
    <xsl:element name="{name()}" namespace="{namespace-uri()}">
       <xsl:value-of select="."/>
    </xsl:element>
  </xsl:for-each>
  <xsl:apply-templates/>
</xsl:template>

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
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
transformation from attributes to nested elements e-bell XSLT 2 January 21st, 2007 07:21 PM
how to control optional elements and attributes NEO1976 XSLT 5 September 4th, 2006 03:58 AM
sequenced elements to attributes zkent XSLT 0 April 19th, 2006 09:50 AM
Elements and attributes Morrislgn XSLT 1 June 20th, 2005 12:13 PM
Elements w same name and their attributes supafly XSLT 1 May 30th, 2005 07:34 AM



All times are GMT -4. The time now is 01:20 PM.


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