Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old July 26th, 2006, 08:15 PM
Foxpointe
Guest
 
Posts: n/a
Default 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
  #2  
Old July 27th, 2006, 02:15 AM
Dimitre Novatchev
Guest
 
Posts: n/a
Default Re: Looking for suggestions (xslt?) on stripping specified elements/attributes from XHTML

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" <foxpointe@comcast.netwrote in message
news:4r6dnX0DdcgVXVrZnZ2dnUVZ_uqdnZ2d@comcast.com. ..
Quote:
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

 

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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 Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles