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 June 10th, 2005, 07:28 AM
Authorized User
 
Join Date: Jun 2005
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!

 
Old June 10th, 2005, 07:56 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="*">
  <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





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 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
Elements w same name and their attributes supafly XSLT 1 May 30th, 2005 06:34 AM





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