F
FrankIsHere
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">
<xslutput 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>
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">
<xslutput 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>