473,785 Members | 2,938 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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;tabl e&gt;
&lt;tr&gt;&lt;t d&gt;&lt;b&gt;F eature&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;t d&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;t d&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;t d&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;t d&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 1814


Figo 775 wrote:

I have an xml document which is as below:
<?xml version="1.0" encoding="UTF-8"?>
<fragment name="htmlPart" >
<value>&lt;tabl e&gt;
&lt;tr&gt;&lt;t d&gt;&lt;b&gt;F eature&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;t d&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;t d&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;t d&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;t d&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;tabl e&gt;
&lt;tr&gt;&lt;t d&gt;&lt;b&gt;F eature&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;t d&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;t d&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;t d&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;t d&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>Feat ure</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;tabl e&gt;
&lt;tr&gt;&lt;t d&gt;&lt;b&gt;F eature&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;t d&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;t d&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;t d&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;t d&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;tabl e&gt;
&lt;tr&gt;&lt;t d&gt;&lt;b&gt;F eature&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;t d&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;t d&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;t d&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;t d&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
3747
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 the appropriate array. For instance if I receive a RCVD_MSG1, I'll copy into msg1 . Upon receipt of the next RCVD_MSG1. I'll copy into msg1 . The Retrieve function when called should retrieve the latest copy. ie. msg1 or msg1 .
16
3014
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 lately I've been wanting to do more stuff with user accounts, and had been eying MySQL for over a year. Finally I've decided to start off small by converting the forum's account system to a MySQL database (and convert the rest later after I'm...
2
1318
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 ASP.NET project. I would like to retrieve either a stream/XmlTextWriter from the Business layer, that i can just retrieve and write from the front end, Whats the best method to do this?
5
6672
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 (In this example 1234-54321) and pass it to a text box on a form. Something like this. <form name="form1" id="form1" method="post" action="">
3
1502
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 HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <% connect_string = "Driver={SQL Server};Server=NLROSDBCL9-10;Database=Scanners;Uid=scanners;Pwd=bertrand;"
3
2664
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. There are 5 colums of data I wish to display. I want to display these records in groups of 10. Based on the fact that the records I want are located in a separate file, how can I get these details to show on the form and manipulate the data to...
4
2206
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 jsData = new Array(); jsData = {bowl:"I", year:1967, winner:"Packers", winScore:35, loser:"Chiefs", losScore:10}; jsData = {bowl:"II", year:1968, winner:"Packers", winScore:33,
1
4223
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 aligned to the top, along with the slideshow and link buttons, you have to scroll down to see the text - how can I make IE6 display correctly? http://geekarama.co.uk/new_home.html here is the code for new_home.html and following that the CSS...
0
2729
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, cannot serch by combine 3 table) Example I have the query table below, how do I make the code to seach based on the query from this: SELECT Product.ID, Product.Description, Quantity.Quantity, Quantity.SeialNo, Quantity.SupplierID,...
0
9480
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10330
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10153
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10093
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8976
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7500
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3654
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2880
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.