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 November 12th, 2009, 11:43 AM
Authorized User
Join Date: Aug 2009
Posts: 11
Thanks: 3
Thanked 0 Times in 0 Posts
Default Change XMLs

I want to export an XML with an attribute name="work" to all XML elements.
Here is the XSLT.
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" />
<xsl:strip-space elements="*" />

<xsl:template match="*">
	<xsl:attribute name="name">work</xsl:attribute>
	<xsl:apply-templates />
	<xsl:copy-of select="." />
Why this doesn't work?
Old November 12th, 2009, 11:48 AM
Friend of Wrox
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts

<xsl:template match="*">
    <xsl:copy-of select="@*/>
    <xsl:attribute name="name">work</xsl:attribute>
might do what you want.
Your attempt does try to create the attribute first (without having any element to create an attribute for), then processes any child elements, then makes a deep copy of the element and all its content.
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
The Following User Says Thank You to Martin Honnen For This Useful Post:
chameleon (November 12th, 2009)
Old November 12th, 2009, 11:53 AM
samjudson's Avatar
Friend of Wrox
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts

xsl:attribute must follow either an output literal, or an xslt instruction that outputs and xml element. xsl:template does neither:

<xsl:attribute name="test">value</xsl:attribute>


<xsl:element name="myelement">
<xsl:attribute name="test">value</xsl:attribute>

What you are probably wanting is something more like this however:

<xsl:template match="node()">
<xsl:attribute name="name" select="'work'"/>
<xsl:apply-templates select="@*|node()"/>

<xsl:template match="@*">
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
The Following User Says Thank You to samjudson For This Useful Post:
chameleon (November 12th, 2009)

Similar Threads
Thread Thread Starter Forum Replies Last Post
Grouping xmls sac XSLT 4 July 29th, 2008 04:16 AM
Multiple xmls and xsls pasupathy.b XSLT 6 June 4th, 2007 01:07 PM
XML element referencing to other xmls alexhinz XSLT 0 February 8th, 2007 09:32 AM
What Do I Change? myself Classic ASP Basics 2 August 1st, 2006 04:01 PM
Why does it change kilika VBScript 0 September 18th, 2003 05:14 PM

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