Connecting Tech Pros Worldwide Help | Site Map

xsl:copy-of not copy element name?

Newbie
 
Join Date: Dec 2008
Posts: 10
#1: Dec 27 '08
I'm using xsl:copy-of because I need to preserve a break tag in my 'description' element (see below). While it does work, it also copies over the <description> tags and puts them in my HTML, which obviously cannot pass W3C validation. Is there any way to copy everything, except for the <description> tags. Or is there a better way? I'm new at this. Thanks...

Sample from .xml file

<item id="MGEBSK">
<title>A Product Title</title>
<description>A Description that is <br/> really important.</description>
</item>


Sample from .xsl transformation file

<xsl:copy-of select="description"/>


HTML output (will not validate):

<description>A Description that is <br/> really important.</description>

Desired HTML output:


A Description that is <br/> really important.
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,629
#2: Dec 27 '08

re: xsl:copy-of not copy element name?


try
Expand|Select|Wrap|Line Numbers
  1. // selects all child nodes of <description>
  2. <xsl:copy-of select="description/node()"/>
regards

PS please use [code] tags when posting code, it's much better readable this way
Newbie
 
Join Date: Dec 2008
Posts: 10
#3: Dec 27 '08

re: xsl:copy-of not copy element name?


Thanks, that worked great!

Any idea why it changed my break tag from <br/> to <br>? Can that be prevented?

Sorry about the [code] tags... I'll make a note of that.
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,629
#4: Dec 27 '08

re: xsl:copy-of not copy element name?


you're probably using html output method.

yes, use xml output method.
Newbie
 
Join Date: Dec 2008
Posts: 10
#5: Dec 28 '08

re: xsl:copy-of not copy element name?


Great! Thanks for your help!
Reply