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

F

Foxpointe

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
 
D

Dimitre Novatchev

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,002
Messages
2,570,261
Members
46,858
Latest member
FlorrieTuf

Latest Threads

Top