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

HTML to XML transform

I'm having some problems converting HTML to XML. Below is the source
document.

<html xmlns:wf="http://sometest/wf">
<head>
<span wf:class="cookie.equals.EntryURL" wf:values="region">
<span class="text_red">
<span wf:class="term.insert" wf:term="Master">United
States</span>
</span>
</span>
</head>
</html>

The logic is find any html tags that contain an attribute with the
namespace "wf". Then get the attribute "class" and use it as a parent
node with the attribute values as a child nodes. It's probably easier
I show you what I want the output to look like.

Below is the format I'm trying to convert the source to:
<docRoot>
<Class>
<classname>cookie.equals.EntryURL</classname>
<attribute aName="values">Region</attribute>
<Class>
<classname>term.insert</classname>
<attribute aName="term">Master</attribute>
<Class>
</Class>
</docRoot>

This is the stylesheet I have so far:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/ | node() | @* ">
<xsl:copy>
<xsl:apply-templates select="@wf:* | node()"
xmlns:wf="http://sometest/wf"/>
</xsl:copy>
</xsl:template>

<xsl:template match="@*">
<xsl:element name="{local-name(.)}" namespace="{namespace-uri(..)}">
<xsl:value-of select="."/>
</xsl:element>
</xsl:template>

</xsl:stylesheet>
It converts it to this:
<?xml version="1.0" encoding="UTF-8"?>
<html xmlns:wf="http://sometest/wf">
<head>
<span>
<class>cookie.equals.EntryURL</class>
<values>region</values>
<span>
<span>
<class>term.insert</class>
<term>Master</term>
United States</span>
</span>
</span>
</head>
</html>
Thanks!

Jul 20 '05 #1
2 1354
Hi,

Tempore 20:41:01, die Wednesday 13 July 2005 AD, hinc in foro {comp.text.xml} scripsit
Fr*********@gmail.com <Fr*********@gmail.com>:
The logic is find any html tags that contain an attribute with the
namespace "wf". Then get the attribute "class" and use it as a parent
node with the attribute values as a child nodes. It's probably easier
I show you what I want the output to look like.


Here's one method, I'm not sure if it will work universally.

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:wf="http://sometest/wf" xmlns="http://sometest/wf">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<docRoot>
<xsl:apply-templates />
</docRoot>
</xsl:template>

<xsl:template match="*[@wf:*]">
<xsl:element name="{local-name(@wf:*[1])}" namespace="{namespace-uri(@wf:*[1])}">
<classname><xsl:value-of select="@wf:*[1]"/></classname>
<xsl:apply-templates select="* | @wf:*[position() &gt; 1]"/>
</xsl:element>
</xsl:template>

<xsl:template match="@wf:*">
<attribute aName="{local-name()}"><xsl:value-of select="."/></attribute>
</xsl:template>

</xsl:stylesheet>
regards,
--
Joris Gillis (http://users.telenet.be/root-jg/me.html)
Spread the wiki (http://www.wikipedia.org)
Jul 20 '05 #2

Joris,

<classname><xsl:value-of select="@wf:*[1]"/></classname>
<xsl:apply-templates select="* | @wf:*[position() &gt; 1]"/>

attribute order is undefined (but stable within a given transformation)
so you can't rely on [1] being the class attribute, you need to pull it
out by name.
<classname><xsl:value-of select="@wf:class"/></classname>
<xsl:apply-templates select="* | @wf:*[local-name()!='class']"/>

David
Jul 20 '05 #3

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

Similar topics

2
by: Antonio Amato | last post by:
Hi, I want to transform XML docbook to HTML with docbook stylesheet (docbook-xsl-1.67.0.zip). I'm using javax.xml.transform.TransformerFactory to apply XSLT to XML but it generates an...
5
by: KathyB | last post by:
If someone could just explain this to me...I just don't get it! I have an aspx page where I retrieve several session variables and use xmlDocument to transform xml file with xsl file into an...
2
by: Ruben | last post by:
Hi, My users creates documents in MS Word 2003, thay save the docs as XML files, and I want to load this XML and transform it to HTML (I mean, I don't want Word to be opened in the browser, I want...
3
by: Rusty | last post by:
Hi, our intranet web site needs to add this feature. I've got the components but just need the last step to get it going. Here's the setup. 1) a user clicks on a link which calls a web service...
4
by: Rick Walsh | last post by:
I have an HTML table in the following format: <table> <tr><td>Header 1</td><td>Header 2</td></tr> <tr><td>1</td><td>2</td></tr> <tr><td>3</td><td>4</td></tr> <tr><td>5</td><td>6</td></tr>...
1
by: vbfoobar | last post by:
Hello, I have HTML input to which I apply some changes. Feature 1: ======= I want to tranform all the text, but if the text is inside an "a href" tag, I want to leave the text as it is. ...
21
by: =?iso-8859-2?Q?K=F8i=B9tof_=AEelechovski?= | last post by:
It is common knowledge that XHTML is better HTML and you can serve XHTML content as HTML. However, the second statement is incorrect, for various reasons; it is enough to say that the HTML...
1
by: MaggotChild | last post by:
Hi, I'm trying to transform the values entered into a form: HTML: <div id="container"> <div id="bs"> <input id="name" type="text"/> <p>PPPPP</p> <a href="#" onclick="return transform()">Do...
2
by: siddun | last post by:
I want to transform an XML file into many HTML files using XSL and JAXP. I am able to successfully generate many HTML files. But when description element is more than one paragraph, I am not able to...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
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: 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:
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
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...

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.