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

xsl to retrieve text in table elements in xml



Hi,
I have an xml document which is as below:
<?xml version="1.0" encoding="UTF-8"?>
<fragment name="htmlPart">
<value>&lt;table&gt;
&lt;tr&gt;&lt;td&gt;&lt;b&gt;Feature&lt;/b&gt;&lt;/td&gt;&lt;td&gt;&lt;b
&gt;Benefit&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;some sample text runs here&lt;/td&gt;&lt;td&gt;some
sample text runs here too&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;some sample text runs here&lt;/td&gt;&lt;td&gt;some
sample text runs here too&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Now I am here &lt;/td&gt;&lt;td&gt;Now what am I
going to do here&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;some stuff lies here too&lt;/td&gt;&lt;td&gt;Please
give suggestions&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
</value>
</fragment>

3 "fragment name ="htmlpart" elements are present in this document..

For each fragment name ="htmlpart", the xsl I need should create an
element "<fragment name="tr"> and map the tr values from the text above
in its "value" element.
The same needs to be done for "td".
Please provide an answer to this.

Thanks,
figo
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #1
4 1788


Figo 775 wrote:

I have an xml document which is as below:
<?xml version="1.0" encoding="UTF-8"?>
<fragment name="htmlPart">
<value>&lt;table&gt;
&lt;tr&gt;&lt;td&gt;&lt;b&gt;Feature&lt;/b&gt;&lt;/td&gt;&lt;td&gt;&lt;b
&gt;Benefit&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;some sample text runs here&lt;/td&gt;&lt;td&gt;some
sample text runs here too&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;some sample text runs here&lt;/td&gt;&lt;td&gt;some
sample text runs here too&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Now I am here &lt;/td&gt;&lt;td&gt;Now what am I
going to do here&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;some stuff lies here too&lt;/td&gt;&lt;td&gt;Please
give suggestions&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
</value>
</fragment>

3 "fragment name ="htmlpart" elements are present in this document..

For each fragment name ="htmlpart", the xsl I need should create an
element "<fragment name="tr"> and map the tr values from the text above
in its "value" element.
The same needs to be done for "td".
Please provide an answer to this.


I am afraid as your XML input doesn't contain <tr> elements or <td>
elements but just text with such tags there is no easy way to process
the input with XSLT/XPath.
All you could do is use the XPath text processing but there are
languages which have more power for text processing than XSLT/XPath 1.0
have.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 20 '05 #2
> I have an xml document which is as below:
<?xml version="1.0" encoding="UTF-8"?>
<fragment name="htmlPart">
<value>&lt;table&gt;
&lt;tr&gt;&lt;td&gt;&lt;b&gt;Feature&lt;/b&gt;&lt;/td&gt;&lt;td&gt;&lt;b
&gt;Benefit&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;some sample text runs here&lt;/td&gt;&lt;td&gt;some
sample text runs here too&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;some sample text runs here&lt;/td&gt;&lt;td&gt;some
sample text runs here too&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Now I am here &lt;/td&gt;&lt;td&gt;Now what am I
going to do here&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;some stuff lies here too&lt;/td&gt;&lt;td&gt;Please
give suggestions&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
</value>
</fragment>


The html encoded as text looks like valid XHMLT, so you should include the html as elements rather than raw text. So the first step would be to unescape the &lt; and &gt; entities. (It can even be done with XSLT)

Once you have this XML:
<fragment name="htmlPart">
<value><table> <tr><td><b>Feature</b></td><td><b >Benefit</b></td></tr> <tr><td>some sample text runs here</td><td>some sample text runs here too</td></tr> <tr><td>some sample text runs here</td><td>some sample text runs here too</td></tr> <tr><td>Now I am here </td><td>Now what am I going to do here</td></tr> <tr><td>some stuff lies here too</td><td>Please give suggestions</td></tr></table>
</value>
</fragment>

the job is easily done with XSLT like this:
<xsl:template match="fragment[@name='htmlPart']">
<value>
<xsl:apply-templates select="value/*"/>
</value>
</xsl:template>

<xsl:template match="tr|td">
<fragment name="{local-name()}">
<value>
<xsl:apply-templates/>
</value>
</fragment>
</xsl:template>
I'm not sure though, if this is really what you mean with "mapping the tr values from the text its "value" element". Please explain a bit clearer what is your goal.

regards,
--
Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
Ceterum censeo XML omnibus esse utendum
Jul 20 '05 #3


Hi Joris,

I think I will be more clearer now though this is a small portion of a
bigger doc. Please let me know if I am not.

<?xml version="1.0" encoding="UTF-8"?>
<fragment name="htmlPart">
<value>&lt;table&gt;
&lt;tr&gt;&lt;td&gt;&lt;b&gt;Feature&lt;/b&gt;&lt;/td&gt;&lt;td&gt;&lt;b
&gt;Benefit&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;some sample text runs here&lt;/td&gt;&lt;td&gt;some
sample text runs here too&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;some sample text runs here&lt;/td&gt;&lt;td&gt;some
sample text runs here too&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Now I am here &lt;/td&gt;&lt;td&gt;Now what am I
going to do here&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;some stuff lies here too&lt;/td&gt;&lt;td&gt;Please
give suggestions&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
</value>
</fragment>

3 "fragment name ="htmlpart" elements are present(similar to the above
format.

My XSL should convert the "htmlpart" element into three elements
<fragment name="tr">
<value>
<fragment name="td">
<value>
<fragment name="tablecell">
<value>
This should contain text between the first '&lt;tr&gt;&lt;tr&gt;'
'&lt;/td&gt;&lt;/tr&gt;'
</value>
</fragment>
....
This structure should be repeated for each content text between
'&lt;tr&gt;&lt;tr&gt;' '&lt;/td&gt;&lt;/tr&gt;' .
So I guess I need to use substring recursively to search for the above
patterns and map content. Hope this gives a better picture. Any help
would be greatly appreciated.
Thanks,
figo
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Jul 20 '05 #4
Hi khp,

I think I will be more clearer now though this is a small portion of a
bigger doc.

<?xml version="1.0" encoding="UTF-8"?>
<fragment name="htmlPart">
<value>&lt;table&gt;
&lt;tr&gt;&lt;td&gt;&lt;b&gt;Feature&lt;/b&gt;&lt;/td&gt;&lt;td&gt;&lt;b
&gt;Benefit&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;some sample text runs here&lt;/td&gt;&lt;td&gt;some
sample text runs here too&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;some sample text runs here&lt;/td&gt;&lt;td&gt;some
sample text runs here too&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Now I am here &lt;/td&gt;&lt;td&gt;Now what am I
going to do here&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;some stuff lies here too&lt;/td&gt;&lt;td&gt;Please
give suggestions&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
</value>
</fragment>

3 "fragment name ="htmlpart" elements are present(similar to the above
format.

My XSL should convert the "htmlpart" element into three elements
<fragment name="tr">
<value>
<fragment name="td">
<value>
<fragment name="tablecell">
<value>
This should contain text between the first '&lt;tr&gt;&lt;tr&gt;'
'&lt;/td&gt;&lt;/tr&gt;'
</value>
</fragment>
....
This structure should be repeated for each content text between
'&lt;tr&gt;&lt;tr&gt;' '&lt;/td&gt;&lt;/tr&gt;' .
Hope this gives a better picture. Any help would be greatly appreciated.
Thanks,
figo


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Jul 20 '05 #5

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

Similar topics

2
by: forums_mp | last post by:
I've got an STL class (see below) with two functions to store and retrieve data - msg structs. The "Store" function when called will copy the received message (depending on which message) into...
16
by: Daniel Tonks | last post by:
First, please excuse the fact that I'm a complete MySQL newbie. My site used forum software that I wrote myself (in Perl) which, up until now, has used flat files. This worked fine, however...
2
by: Grant Merwitz | last post by:
I am trying to write an XML file from my database. Currently, i have this code on an ASPX page, but have also built a business layer that manages all the DataRetrieval and is reference in my main...
5
by: bobdydd | last post by:
Hi Everybody I have an Access database that passes a Parameter to a web page something like this. http://localhost/index.htm?paramName=1234-54321 I want to be able to retrieve the parameter...
3
by: bazubwabo | last post by:
hi everybody , could u please help me to find out the error on my asp codes,i can't retrieve the inserted values. Here is below the code: <%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%> <!DOCTYPE...
3
by: jonniethecodeprince | last post by:
Hi all, I have trouble getting an array of data stored in a separate javascript file i.e. a file called books.js into a table of data for a .xhtml file. There are 50 Records in this file....
4
by: Harry | last post by:
Hi Guys I dont really know how to do this: if there are a page of others, some data are embedded inside the data array like this: <script language="JavaScript" type="text/javascript"> <!-- var...
1
by: littlealex | last post by:
IE6 not displaying text correctly - IE 7 & Firefox 3 are fine! Need some help with this as fairly new to CSS! In IE6 the text for the following page doesn't display properly - rather than being...
0
by: JamesOo | last post by:
I have the code below, but I need to make it searchable in query table, below code only allowed seach the table which in show mdb only. (i.e. have 3 table, but only can search either one only,...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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...
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,...

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.