Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > XSLT: outputting element contents without containing tags

Reply
Thread Tools

XSLT: outputting element contents without containing tags

 
 
Francis Hwang
Guest
Posts: n/a
 
      12-20-2003
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"
xmlnssl="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
 
Reply With Quote
 
 
 
 
Dimitre Novatchev
Guest
Posts: n/a
 
      12-20-2003

"Francis Hwang" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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


 
Reply With Quote
 
 
 
 
Patrick TJ McPhee
Guest
Posts: n/a
 
      12-20-2003
In article <(E-Mail Removed) >,
Francis Hwang <(E-Mail Removed)> 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
http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
Francis Hwang
Guest
Posts: n/a
 
      12-21-2003
(E-Mail Removed) (Patrick TJ McPhee) wrote in message news:<bs2m9o$sqq$(E-Mail Removed)>...
> In article <(E-Mail Removed) >,
> Francis Hwang <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding contents on yaml file without overwriting actual contents Kamarulnizam Rahim Ruby 4 01-28-2011 09:10 AM
how to Update/insert an xml element's text----> (<element>text</element>) HANM XML 2 01-29-2008 03:31 PM
data containing html tags appears in gridview jamesd ASP .Net Web Controls 1 06-02-2006 05:23 PM
Accessibility and Validating LINK tags containing "&amp;" Lemming HTML 3 10-19-2004 11:13 PM
Can I restrict both attribute contents and element contents in schema Don Adams XML 1 03-05-2004 12:48 PM



Advertisments