473,386 Members | 1,860 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,386 software developers and data experts.

HTML Via XSLT to Plain Text output

Hi All.
I'm trying to transform a html document into plain text via xslt.
Simple you say! (i hope)
I have got it working, by using the magnificent <xsl:value-of select="."/>.
This returns the whole document, and <xsl:output method="text"/> ensures that the output I get is plain text.
problem:
The html I am transforming has a table, with headings and data. Whilst the output contains all the data form the table, it does not preserve any formatting, and concatenates all the data within the table.
Can you suggest how i could extract the data from the table, and present in plain text? The only formatting I require, is that the spacing between the columns is somewhat preserved.
I am, as im sure you can tell, an xslt noob still, even with many years of application development under my belt!.
Thanks for all your help!

Xslt:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="text"/>
<xsl:template match="/">
<xsl:value-of select="."/>
<xsl:value-of select="normalize-space(.)"/>
</xsl:template>
</xsl:stylesheet>

Html:

<HTML xmlns="http://www.w3.org/1999/xhtml">
<HEAD></HEAD>
<BODY>
<p>Dear person,</p>
<p>The following are columns are required to preserve the formatting.</p>
<table cellpadding="0" cellspacing="0" width="50%">
<tr>
<td width="20%">Column 1</td>
<td width="25%">Column 2</td>
<td width="20%">Column 3</td>
<td width="20%">Column 4</td>
</tr>
<tr>
<td><font size="4">01/06/2008</font></td>
<td><font size="4">34.2</font></td>
<td><font size="4">A Name</font></td>
<td><font size="4">42.00</font></td>
</tr>
</table>
</BODY>
</HTML>


result:
somethign like...

Dear person, The following are columns are required to preserve the formatting. Column 1Column 2Column 3Column 401/06/200834.2A Name42.00
;
Any suggestions would be welcome:)
Oct 3 '07 #1
3 9490
Hi I'm also noob, but I manage to find this code for space

You can try adding this within the template:
<xsl:value-of select="'&#x20;'" />
or
<xsl:text> </xsl:text>

Hope it helps.

Cheers,
Gaiason

Hi All.
I'm trying to transform a html document into plain text via xslt.
Simple you say! (i hope)
I have got it working, by using the magnificent <xsl:value-of select="."/>.
This returns the whole document, and <xsl:output method="text"/> ensures that the output I get is plain text.
problem:
The html I am transforming has a table, with headings and data. Whilst the output contains all the data form the table, it does not preserve any formatting, and concatenates all the data within the table.
Can you suggest how i could extract the data from the table, and present in plain text? The only formatting I require, is that the spacing between the columns is somewhat preserved.
I am, as im sure you can tell, an xslt noob still, even with many years of application development under my belt!.
Thanks for all your help!

Xslt:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="text"/>
<xsl:template match="/">
<xsl:value-of select="."/>
<xsl:value-of select="normalize-space(.)"/>
</xsl:template>
</xsl:stylesheet>

Html:

<HTML xmlns="http://www.w3.org/1999/xhtml">
<HEAD></HEAD>
<BODY>
<p>Dear person,</p>
<p>The following are columns are required to preserve the formatting.</p>
<table cellpadding="0" cellspacing="0" width="50%">
<tr>
<td width="20%">Column 1</td>
<td width="25%">Column 2</td>
<td width="20%">Column 3</td>
<td width="20%">Column 4</td>
</tr>
<tr>
<td><font size="4">01/06/2008</font></td>
<td><font size="4">34.2</font></td>
<td><font size="4">A Name</font></td>
<td><font size="4">42.00</font></td>
</tr>
</table>
</BODY>
</HTML>


result:
somethign like...

Dear person, The following are columns are required to preserve the formatting. Column 1Column 2Column 3Column 401/06/200834.2A Name42.00
;
Any suggestions would be welcome:)
Oct 3 '07 #2
jkmyoung
2,057 Expert 2GB
Instead of using <xsl:value-of select="."/>
I suggest using <xsl:apply-templates/>
Then have 2 templates like so:
Expand|Select|Wrap|Line Numbers
  1. <xsl:template match="tr">
  2.   <xsl:apply-templates/>
  3.     <xsl:text>
  4. </xsl:text><!-- add a newline -->
  5. </xsl:template>
  6.  
  7. <xsl:template match="td">
  8.   <xsl:text> </xsl:text>
  9.     <xsl:apply-templates/>
  10.   <xsl:text> </xsl:text>
  11. </xsl:template>
Oct 3 '07 #3
Thanks for your replies, I will give it a go.
Might just use regex to strip out all html tags, seems to work ok for our needs.
Oct 4 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Pete | last post by:
I am just getting to grips with XML and I was wondering if you could help me with something that no-one seems able or willing to help with.. I have an XSLT file which should be transforming a...
3
by: pradeep gummi | last post by:
I have an XML FILE that is to be converted to Plain Text using an XSL file. Since I just want plain text, I do not want to set any root element during transformation.And if I do not any root...
2
by: nanookfan | last post by:
Hi all, I'm having a bizarre problem converting XML files to HTML using an XSLT. The problem is only occuring in my Netscape 7.0 browser. What makes it more bizarre is that it is only...
1
by: shea | last post by:
I have an XML data type which I would like to display in my HTML. The data type looks somthing like this: <package name="helloworld"> <description> This is a program which prints hello world to...
3
by: Andy | last post by:
Hi all, I'm having a problem doing an Xslt transform in code. I've done it before, so I'm not really sure why its not working. The problem is that the result of the transform is an empty...
5
by: eva.mukhija | last post by:
Hi I need to insert some html content generated by certain business logic into an xsl output. I have been able to insert custom Java extensions and generate the HTML to be outputted. My problem...
12
by: Chris | last post by:
Hi, Just wondering if anyone out there knows if it is possible to convert a CSV to xml using XSLT? I've seen a lot of examples of xml to CSV, but is it possible to go back the other way? I...
6
by: ronburk | last post by:
Is there any standard way to control the end-of-line convention (LF versus CR/LF) for XSLT processor output? The obvious logical point to control this would be in xsl:output. However, Kay says...
4
by: mark4asp | last post by:
I have an element, report which contains tags which have been transformed. E.g. <pis &lt;p&gt <myXml> <report>This text has html tags in it.&lt;p&gt which but <has been changed to &lt;&gt</report>...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: 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
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
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,...

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.