Advertisement

06.03.2006 at 02:27PM PDT, ID: 21873645
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.2

Converting XML elements to attributes

Asked by mircea_a in Extensible Markup Language (XML), Extensible HTML (XHTML)

Tags: , , ,

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("Microsoft.XMLDOM")
xml.async = false
xml.load(Server.MapPath("cd_catalog.xml"))

'Load the XSL
set xsl = Server.CreateObject("Microsoft.XMLDOM")
xsl.async = false
xsl.load(Server.MapPath("cd_catalog.xsl"))

Response.Write(xml.transformNode(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:value-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
[+][-]06.04.2006 at 12:53AM PDT, ID: 16826493

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Extensible Markup Language (XML), Extensible HTML (XHTML)
Tags: encoding, stylesheet, may, xml
Sign Up Now!
Solution Provided By: Gertone
Participating Experts: 2
Solution Grade: A
 
 
[+][-]06.04.2006 at 03:02AM PDT, ID: 16826688

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.04.2006 at 10:40AM PDT, ID: 16827892

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.04.2006 at 10:54AM PDT, ID: 16827942

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32