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 December 12th, 2007, 11:20 PM
Registered User
 
Join Date: Dec 2007
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default XSL(T) problems with xsl:element

Hi guys,

I'm pretty new to XSLT so please bare with me. I'm trying to output an XML trough XSLT to a new XML. The output XML has the same structure etc. as the source XML. However, within the transformation I filter out some stuff. I do not know what tags are being used in the source XML. I only know the structure which to filter. So, I would use something like this template the recursively go trough the source and output it as it was:
Code:
<xsl:template match="*">
    <xsl:element name="???">
        <xsl:apply-templates />
    </xsl:element>
</xsl:template>
The problem is that I need to original name of the node currently being processed for the 'name' attribute of the <xsl:element> tag. How do I get this name (and the attributes as well). Basically a 1:1 copy.

Thanks!


 
Old December 13th, 2007, 01:51 AM
Registered User
 
Join Date: Dec 2007
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Searching for days, then you finally reach out for help you obviously find it yourself. It should be:
Code:
<xsl:template match="*">
    <xsl:element name="{name()}">
        <xsl:apply-templates />
    </xsl:element>
</xsl:template>
Notice the '{name()}' in the <xsl:element> tag... Of course, I'm still looking for a way to echo the attributes as well.
 
Old December 13th, 2007, 05:58 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Most people use the identity transform:

<xsl:template match="node()|@*">
   <xsl:copy>
   <xsl:apply-templates select="@*"/>
   <xsl:apply-templates/>
   </xsl:copy>
 </xsl:template>

/- Sam Judson : Wrox Technical Editor -/
 
Old December 13th, 2007, 06:24 AM
Registered User
 
Join Date: Dec 2007
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

That is a very elegant solution. It works and I will study it. Thank you very much!







Similar Threads
Thread Thread Starter Forum Replies Last Post
embedded <xsl:element> into <xsl:with-param> petergoodman XSLT 2 July 9th, 2008 06:36 AM
How to use xsl:element tag??? NewToXSL XSLT 2 June 8th, 2006 05:54 PM
xsl element identification vakorde XSLT 4 May 7th, 2006 04:48 AM
Sorting element in xsl Sakubar Sathik XSLT 5 April 6th, 2006 04:23 AM
XSL Transform with xsl string NOT xsl file skin XSLT 0 June 16th, 2003 07:30 AM





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