473,569 Members | 2,692 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_conten t">
<xsl:copy-of select="page_co ntent" />
</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>n othing much here.</page_content>

or

<page_content>H ere's the list of every book I ever read:
<ol>
<li><cite>Ulyss es</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 1897

"Francis Hwang" <se**@fhwang.ne t> wrote in message
news:7b******** *************** ***@posting.goo gle.com...
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.ne t> 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_co ntent" />

try

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

--

Patrick TJ McPhee
East York Canada
pt**@interlog.c om
Jul 20 '05 #3
pt**@interlog.c om (Patrick TJ McPhee) wrote in message news:<bs******* ***@news.eusc.i nter.net>...
In article <7b************ **************@ posting.google. com>,
Francis Hwang <se**@fhwang.ne t> 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_co ntent" />

try

<xsl:copy-of select="page_co ntent/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
5056
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 HREF="dfksdfaj">go</A> I want the output from XSLT processing of the SECTION elements to output
5
3110
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 the defined contents of the TABLE element. The TR element is not defined as an "immediate" or "direct" contained element of TABLE. Given that
8
6002
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 ASP.NET tags and HTML tags. <%@ Page Language= etc...
3
1752
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 transform. At the moment the tags are being ignored. I don't want to put the contents inside CDATA because I want to be able to parse the xml file as...
4
1509
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 (yes, the 64832th one, I know). I want to allow some simplified HTML as input language, and use some xsl
4
1791
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 http://rep.oio.dk/Microsoft.com/officeschemas/welcome.htm) to a reasonably clean (X)HTML format. (The reason being that, combined with some PHP scripting it should be possible to store the embedded...
18
2058
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 look up what each feature depends on and gerenate a text file. For example, in the following file, I would like to find out feature A depends on A1...
11
2068
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 doing a contains of the current string against the following-sibling::* to determine if we have duplicates. If we have a duplicate, we move to the...
0
8122
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7673
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7970
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6284
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5513
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5219
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3640
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
937
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.