XSLT: outputting element contents without containing tags

Francis Hwang

Usenet Archive
Joined
Aug 3, 2003
Messages
301
Reaction score
0
Hi,

Maybe this is a newbie question, but: Is there a way to output an element's contents -- including contained nodes and free-form text -- without the containing tags?

I can imagine that this request might be against the spirit of XML in general, but the reason I'm trying to do this is that I want to use XSLT for simple generation of XHTML. Basically I want the page's contents in external files, then I want to include them into a wrapper of the basics (header info, site navigation, etc.) using XSLT. (Of course you could also just use something else like server-side includes for this but I like the idea of XSLT implicitly forcing well-formedness on the documents it processes.) So I have an XSL file that looks like:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xsl:version="1.0"> <head> <title>My web site</title> </head> <body> <p id="page_head"> <!--- page header graphic ---> </p> <hr /> <div id="page_content"> <xsl:copy-of select="page_content" /> </div> <div id="site_nav"> <!--- site navigation ---> </div> </body> </html>

and I want to be able to process a bunch of different files where I know nothing about them except for that their root element is <page_content>. Could be:

<page_content>nothing much here.</page_content>

or

<page_content>Here's the list of every book I ever read:
<ol>
<li><cite>Ulysses</cite> by James Joyce</li>
<!--- more books --->
</ol>
</page_content>

xsl:value-of strips out any contained tags. xsl:copy-of retains all the contained XML tags, but it also keeps the <page_content> tag, of course, meaning that it shows up in the final XHTML. Is there a way to say "whatever's in this element, include it all in order, but don't actually include 'page_content' at the beginning or the end" ?

Thanks in advance,
Francis
 

Dimitre Novatchev

Usenet Archive
Joined
Nov 7, 2000
Messages
737
Reaction score
0

Patrick TJ McPhee

Usenet Archive
Joined
Apr 2, 2000
Messages
269
Reaction score
0
% Maybe this is a newbie question, but: Is there a way to output an % element's contents -- including contained nodes and free-form text -- % without the containing tags?

[...]

Instead of

% <xsl:copy-of select="page_content" />

try

<xsl:copy-of select="page_content/node" />
 

Francis Hwang

Usenet Archive
Joined
Aug 3, 2003
Messages
301
Reaction score
0
% Maybe this is a newbie question, but: Is there a way to output an % element's contents -- including contained nodes and free-form text -- % without the containing tags?

[...]

Instead of

% <xsl:copy-of select="page_content" />

try

<xsl:copy-of select="page_content/node" />

Ah, that helps, thanks. Now all the elements inside of page_content are showing up, but they're getting xmlns attributes. Instead of <p> I get <p xmlns="">. What should I do to stop those from showing up?

Francis
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
548,208
Messages
3,104,798
Members
249,594
Latest member
henrywalsh

Latest Threads

Top