473,396 Members | 2,014 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

XSLT: outputting element contents without containing tags

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
3 1885

"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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Joe | last post by:
How would you preserve tags from an XML element in XSLT output.. Example: XML document has an ELEMENT "SECTION" allowing contained HTML This element might have an element such as <A...
5
by: Patient Guy | last post by:
In my reading of the Strict and Transitional DTD for HTML 4.0, the table row (TR) elements are contained within table section elements: THEAD, TFOOT, and TBODY. The table section elements are...
8
by: Kathleen Dollard | last post by:
Hi, Oleg's answer about attribute value templates led me to look back at a different problem, and wonder if someone else had solved it. I want to output an ASP.NET page. Thus I need to output...
3
by: Andrew Jocelyn | last post by:
Hi Is there a way of outputting some xml tags during an XSLT transform? For example when I use the 'xsl:value-of select="xhtml"' statement I'd like to output the children of 'xhtml' after the...
4
by: Adrian von Bidder | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Yo! Mostly as a finger-exercise (and because I'm annoyed again and again how bad the existing solutions are), I'm hacking up a web-based forum...
4
by: dwergkees | last post by:
Hi, Got a litte problem here. I'm trying to create a XSLT file that will do a transformation from WordML format (MS Word XML format, see...
18
by: yinglcs | last post by:
Hi, I have a newbie XSLT question. I have the following xml, and I would like to find out the children of feature element in each 'features' element. i.e. for each <featuresI would like to...
11
by: =?ISO-8859-1?Q?Jean=2DFran=E7ois_Michaud?= | last post by:
Context: I'm trying to compare XML tree fragments and I'm doing so by outputting the attributes of each element in the tree and outputting it to a string then normalizing the strings. Then I'm...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.