Hi there!
I am trying to convert the elements of an XML to attributes.
For example, the original XML looks like
<?xml version="1.0" encoding="ISO8859-1" ?>
<CATALOG>
<CD>
<TITLE>Empire Burlesque</TITLE>
<ARTIST>Bob Dylan</ARTIST>
<COUNTRY>USA</COUNTRY>
<COMPANY>Columbia</COMPANY
>
<PRICE>10.90</PRICE>
<YEAR>1985</YEAR>
</CD>
<CD>
<TITLE>Hide your heart</TITLE>
<ARTIST>Bonnie Tylor</ARTIST>
<COUNTRY>UK</COUNTRY>
<COMPANY>CBS Records</COMPANY>
<PRICE>9.90</PRICE>
<YEAR>1988</YEAR>
</CD>
I need the final one to look like:
"<CD TITLE="Empire Burlesque" ARTIST="Bob Dylan" COUNTRY="USA" COMPANY="Columbia" PRICE="10.90" YEAR="1985"></CD>
<CD TITLE ="Hide your heart" .. and so on"
I am using the following ASP:
<%
'Load the XML
set xml = Server.CreateObject("Micro
soft.XMLDO
M")
xml.async = false
xml.load(Server.MapPath("c
d_catalog.
xml"))
'Load the XSL
set xsl = Server.CreateObject("Micro
soft.XMLDO
M")
xsl.async = false
xsl.load(Server.MapPath("c
d_catalog.
xsl"))
Response.Write(xml.transfo
rmNode(xsl
))
%>
And XSL:
<?xml version=`1.0`?>
xmlns:xsl="
http://www.w3.org/XSL/Transform/1.0";
default-space="strip"
indent-result="yes">
<xsl:template match="*">
<xsl:copy>
<xsl:for-each select="CD">
<xsl:attribute name="{name(.)}"><xsl:valu
e-of select="."/>
</xsl:attribute>
</xsl:for-each>
<xsl:apply-templates select="*[* or @*]|text()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
But I get the following error:
"msxml3.dll error '80004005'
The stylesheet does not contain a document element. The stylesheet may be empty, or it may not be a well-formed XML document.
/xsl/convert.asp, line 12"
Does anyone know what's wrong in the above code? Or do you happen to have another method to convert XML elements to attributes using either ASP or PHP and of course XSL?
Thank you,
Mircea
Start Free Trial