473,406 Members | 2,705 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,406 software developers and data experts.

Looking for suggestions (xslt?) on stripping specified elements/attributesfrom XHTML

Given some arbitrary XHTML, I'd like to obtain a 'simplified' XHTML
result which strips out a large subset of standard elements and
attributes - but not all. The main things I would like to accomplish:

1) Provide a list of elements/attributes to be stripped (i.e. everything
else should be passed through) or those that should be passed through
(i.e. everything else should be stripped) which would be applied
recursively.
2) If an element is to be stripped, pass through any enclosed text
and/or elements (the elements should in turn be processed recursively by
step 1.)
3) If after stripping the resulting element is empty, eliminate it
completely.

For example, this snippet:

<h1>
<a href='chap2.htm'>
<img src="image.gif" alt="Thumbnail" border=0>
</a>
</h1>
<table width=515 border=0 cellpadding=0 cellspacing=0>
<tr>
<td width=172 align=left valign=top>
<a href="chap1.htm">
<img src="prev.gif" alt="Previous" border=0>
</a>
</td>
<td>
<style type="text/css">
</style>
</td>
<td width=171 align=center valign=top>
<b>
<font face="ariel,helvetica,helv,sanserif" size="-1">Chapter 2 Getting
Started</font>
</b>
</td>
<td width=172 align=right valign=top>
<a href="chap3.htm">
<img src="next.gif" alt="Next" border=0>
</a>
</td>
</tr>
</table>

Would become:

<a href='chap2.htm'>
<img src="image.gif">
</a>
<table>
<tr>
<td>
<a href="chap1.htm">
<img src="prev.gif" alt="Previous">
</a>
</td>
<td>
Chapter 2 Getting Started
</td>
<td>
<a href="chap3.htm">
<img src="next.gif" alt="Next">
</a>
</td>
</tr>
</table>

Is XSLT the best means to accomplish this? Suggestions on how to get
this done (esp. examples that could be used as a starting point) are
appreciated.

Thanks,
Phil
Jul 26 '06 #1
1 1246
Search for and read about "XSLT identity rule" or "XSLT identity
transformation".

It is the most fundamental design pattern in XSLT to override the identity
rule in order to globally delete/replace ... etc. certain subset of nodes,
leaving the general structure and other nodes of the document the same.
Cheers,
Dimitre Novatchev

"Foxpointe" <fo*******@comcast.netwrote in message
news:4r******************************@comcast.com. ..
Given some arbitrary XHTML, I'd like to obtain a 'simplified' XHTML result
which strips out a large subset of standard elements and attributes - but
not all. The main things I would like to accomplish:

1) Provide a list of elements/attributes to be stripped (i.e. everything
else should be passed through) or those that should be passed through
(i.e. everything else should be stripped) which would be applied
recursively.
2) If an element is to be stripped, pass through any enclosed text and/or
elements (the elements should in turn be processed recursively by step 1.)
3) If after stripping the resulting element is empty, eliminate it
completely.

For example, this snippet:

<h1>
<a href='chap2.htm'>
<img src="image.gif" alt="Thumbnail" border=0>
</a>
</h1>
<table width=515 border=0 cellpadding=0 cellspacing=0>
<tr>
<td width=172 align=left valign=top>
<a href="chap1.htm">
<img src="prev.gif" alt="Previous" border=0>
</a>
</td>
<td>
<style type="text/css">
</style>
</td>
<td width=171 align=center valign=top>
<b>
<font face="ariel,helvetica,helv,sanserif" size="-1">Chapter 2 Getting
Started</font>
</b>
</td>
<td width=172 align=right valign=top>
<a href="chap3.htm">
<img src="next.gif" alt="Next" border=0>
</a>
</td>
</tr>
</table>

Would become:

<a href='chap2.htm'>
<img src="image.gif">
</a>
<table>
<tr>
<td>
<a href="chap1.htm">
<img src="prev.gif" alt="Previous">
</a>
</td>
<td>
Chapter 2 Getting Started
</td>
<td>
<a href="chap3.htm">
<img src="next.gif" alt="Next">
</a>
</td>
</tr>
</table>

Is XSLT the best means to accomplish this? Suggestions on how to get this
done (esp. examples that could be used as a starting point) are
appreciated.

Thanks,
Phil

Jul 27 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jesper Moth | last post by:
The MSXML4 xslt-parser would output any source <div/> like this: <div></div> I never figured out how to disable this behaviour. But since it makes the source document look cleaner, and since...
5
by: Greg | last post by:
Hi everybody, so, I would like to use XML files for some parts of my website. I would like to respect W3C XHTML 1.1 recommendation. Then, I have these two docs : o My XML file: <?xml...
6
by: Rainer Herbst | last post by:
Hi *, please consider the following problem: I have a XML document which includes some html elements. I want to replace only the <div> element: I specified two templates, one matches...
20
by: Bernd Fuhrmann | last post by:
Hi! I have some trouble with some simple stupid XSLT-stuff. My stylesheet: ------------- <?xml version="1.0" encoding="iso-8859-1"?> <xsl:stylesheet version="1.0"...
1
by: Bartek | last post by:
Hello This is my problem: It consider xml 2 xml conversion. source document had unknown structure (xhtml), xslt must process every node, attribute, text, comments etc. from source and write in...
21
by: =?iso-8859-2?Q?K=F8i=B9tof_=AEelechovski?= | last post by:
It is common knowledge that XHTML is better HTML and you can serve XHTML content as HTML. However, the second statement is incorrect, for various reasons; it is enough to say that the HTML...
3
by: Andy Dingley | last post by:
>From a thread over in c.i.w.a.h "RFC: From XHTML to HTML via XSLT" http://groups.google.co.uk/group/comp.infosystems.www.authoring.html/msg/f112c230061ffe86 As is well-known, the XSLT HTML...
7
by: C.W.Holeman II | last post by:
For info on the context of my question see the end of this posting. From http://www.w3.org/TR/XHTMLplusMathMLplusSVG/: How can I validate the result of client-side XSLT transform which has...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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,...
0
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...

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.