Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
| 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 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 4th, 2006, 06:34 AM
Registered User
Join Date: Jun 2006
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Copy source-element to output tree

i am trying to do a simple template engine in XSLT to separate content from structure/design. I don't want do invent a whole new XML language for that, so I want to stick to XHTML.

Basically, I have an XML file like this:

<title>Test Entry</title>


I want the result to be like this:
<title>Test Entry</title>
<h1>Test Entry</h1>

How can I achieve this? I use the client-side XSLT transformation of Mozilla 1.5. When I experimented with the following, called from another template, Mozilla complained about the recursive loop.

 <xsl:template name="all" match="*">
    <xsl:element name="{local-name()}">
    <xsl:copy-of select="@*"/>

    <xsl:call-template name="all"/>

Old June 4th, 2006, 03:45 PM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts

You seem to be trying to reinvent for yourself the concept of an identity template. The most usual form of identity template is

<xsl:template match="*">
  <xsl:copy-of select="@*"/>

Note that apply-templates processes the children of the context item, so this does a depth-first tree walk - it's recursive, but it terminates.

An identity template is useful if you want to override it for selected elements within a subtree. If you just want to copy an XHTML subtree without change, use xsl:copy-of.

Michael Kay
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Old June 9th, 2006, 08:17 AM
Registered User
Join Date: Jun 2006
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts

Thanks, i got it working now.

Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy element into complexType in XSLT 2BOrNot2B XSLT 3 December 20th, 2006 09:09 AM
how to exclude elements in the result tree output ntmt XSLT 0 May 25th, 2006 10:33 AM
Can display output as Element name HareshVani XSLT 2 March 22nd, 2006 03:19 AM
xsl:element not on its own line in output EstherMStrom XSLT 3 February 26th, 2005 06:08 AM
copy-of with disable-output-escaping? andrin XSLT 5 July 16th, 2004 04:46 AM

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