(Should Be) Simple XSLT Query Problem

Here should go questions about transforming XML with XSLT and FOP.
wraezor
Posts: 1
Joined: Fri Sep 23, 2005 8:30 am

(Should Be) Simple XSLT Query Problem

Post by wraezor »

Hey folks,

I'm working on an XSLT file here and running into a bit of a problem. Take the following XML source:

Code: Select all

<note>
<title>Hello</title>
<body>This is the body of the text <div>including HTML tags</div>.</body>
</note>
How would I go about selecting the contents of <body> (including _all_ nodes underneath it) into a variable.

As far as I've gotten is (from 'body' scope):
<xsl:variable name="varBody" select="descendant-or-self::*" />

That gives me all the contents (including children & grandchildren), but I'm missing the nodes/tags.

What I want:
"This is the body of the text <div>including HTML tags</div>"

What I'm getting:
"This is the body of the text including HTML tags"

How should I be referencing it? I heard mention of 'xsl:copy-of' but couldn't produce anything different from above when trying it. Seems like it should be simple enough, but I'm stuck.

Thanks in advance.
Radu
Posts: 9049
Joined: Fri Jul 09, 2004 5:18 pm

Post by Radu »

Hi,

"xsl:copy-of" is the way to go.
The following sample stylesheet would accomplish the intended result:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
<xsl:copy-of select="note/body/*"/>
</xsl:template>
</xsl:stylesheet>
You can see the differences between copy and copy-of here:
http://www.w3schools.com/xsl/el_copy-of.asp
http://www.w3schools.com/xsl/el_copy.asp

Regards, Radu.
Post Reply