Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   XML (http://www.velocityreviews.com/forums/f32-xml.html)
-   -   HTML to XML transform (http://www.velocityreviews.com/forums/t169588-html-to-xml-transform.html)

FrankIsHere@gmail.com 07-13-2005 06:50 PM

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>



All times are GMT. The time now is 11:04 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.