Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Sorting XML using XSL loading the xml string



I think I see the problem.

request.responseText;

returns just a string. You won't be able to do anything with it except string manipulations.
What you need is

request.responseXML;

which returns a DOM object containing all data.
I'm not familiar with XSLT but I've been playing around a little with XML and sorting and such stuff.

You may want to see my experimental page :
http://phobbos.homeip.net/~kwasmich/logfile/Untitled.xml

It just consists of a CSS, JS and XML file and works great with WebKit and Opera (and less good with other engines).

Hope this information is some sort of useful :)

Greetings

Michael


Am 02.01.2007 um 14:18 schrieb Mark Spidle:

Thanks Michael,

here is a little more of my code:

I am using xmlhttpreq to get the xml returned from the server/database, this is all working fine.  I want to sort this returned data though.   The result is like so:
=====================
strResult=request.responseText;
var sortedXML = sortXML(strResult);
=====================
Then I call my sort function.  You are right about the not knowing about the load() method.  I now need to find a way to duplicate the whole "new ActiveXObject("Microsoft.XMLDOM")" functionality.  This looks very simple on Windows, unfortunately.

Thanks for the help.

Mark


On Jan 2, 2007, at 1:35 AM, Michael Kwasnicki wrote:

Hello Mark,

it would be great to know how sortXML(xmlDoc) is called.
What type is xmlDoc ?
If it is just an URL it fails.
To load an XML file you will need something like Apple provides at "http://developer.apple.com/internet/webcontent/xmlhttpreq.html".
Anyway the variables xml and xsl do not know the method .load().

since apple provides only an asynchronous exsample, which might be not easy to handle, you may want to try this :

function loadXLM( url ) {
var xmlHttp = new XMLHttpRequest();
xmlHttp.open("GET", url, false);
xmlHttp.send(null);

if (xmlHttp.readyState == 4) {
//the following if statement only works if the URL really points to a WebServer
//if (xmlHttp.status == 200) {
return xmlHttp.responseXML;
//}
}
}

Hope that helps.

Michael



I am queirying a server and getting a returned xml string within in a soap wrapper.  I have done some searching and found that I can then sort the data using and XSL style sheet.

My problem is this, I am trying to load both my xml string and then the xsl string and do the transformNode then return the sorted xml and display it in my widget.

I keep getting the undefined value _javascript_ error about my loaded xml string.  Here is the code:

=======================
I pass in the xml string and the debug displays it fine.

function sortXML(xmlDoc){

DEBUG("the passed xml is " + xmlDoc);
var myXSLtemplate = "<<?xml version='1.0'?>\n\
<xsl:stylesheet xmlns:xsl=\"http://www.w3.org/TR/WD-xsl\">\n\
<xsl:template match=\"/\">\n\
    <table border=\"2\" bgcolor=\"yellow\">\n\
      <tr>\n\
        <th>Title<\/th>\n\
        <th>Artist<\/th>\n\
      <\/tr>\n\
      <xsl:for-each select=\"CATALOG/CD\" order-by=\"+ ARTIST\">\n\
      <tr>\n\
        <td><xsl:value-of select=\"TITLE\"/><\/td>\n\
        <td><xsl:value-of select=\"ARTIST\"/><\/td>\n\
      <\/tr>\n\
      <\/xsl:for-each>\n\
    <\/table>\n\
<\/xsl:template>\n\
<\/xsl:stylesheet>";

// Load XML
var xml;
xml.load(xmlDoc);   HERE IS WHERE THE _javascript_ ERRORS "undefined value"

// Load the XSL
var xsl;
xsl.load(myXSLtemplate);

// Transform
var sortedXML = xml.transformNode(xsl);

return sortedXML;


}
======================

Any help is appreciated.

Mark
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Dashboard-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden



 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Dashboard-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/dashboard-dev/email@hidden

This email sent to email@hidden

References: 
 >Re: Sorting XML using XSL loading the xml string (From: Michael Kwasnicki <email@hidden>)
 >Re: Sorting XML using XSL loading the xml string (From: Mark Spidle <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.