By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,246 Members | 1,451 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,246 IT Pros & Developers. It's quick & easy.

XSLT: outputting element contents without containing tags

P: n/a
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
Jul 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a

"Francis Hwang" <se**@fhwang.net> wrote in message
news:7b**************************@posting.google.c om...
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?


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

will produce all node-children of the current node.
Dimitre Novatchev.
FXSL developer, XML Insider,

http://fxsl.sourceforge.net/ -- the home of FXSL
Resume: http://fxsl.sf.net/DNovatchev/Resume/Res.html
Jul 20 '05 #2

P: n/a
In article <7b**************************@posting.google.com >,
Francis Hwang <se**@fhwang.net> wrote:

% 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()" />

--

Patrick TJ McPhee
East York Canada
pt**@interlog.com
Jul 20 '05 #3

P: n/a
pt**@interlog.com (Patrick TJ McPhee) wrote in message news:<bs**********@news.eusc.inter.net>...
In article <7b**************************@posting.google.com >,
Francis Hwang <se**@fhwang.net> wrote:

% 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
Jul 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.