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



Mark, there may be other issues working against you here, but i did notice a problem with your XSLT code that will def. prevent this from working in this line:

      <xsl:for-each select="CATALOG/CD" order-by="+ ARTIST">

In XSLT, there is *no* "order-by" attribute for the xsl:for-each element. This is not how you perform sorting in XSLT. To sort in XSLT, use the xsl:sort element within an xsl:for-each or xsl:apply-templates instruction. Here is the specification for the xsl:sort element:

<xsl:sort select="Expr"
data-type="«text»|«number»|QName"
order="«ascending»|«descending»"
case-order="«upper-first»|«lower-first»"
lang="lang-code"/>


So your code should look something like this (not sure what that "+" symbol in your code is for):

...
        <xsl:for-each select="CATALOG/CD">
<xsl:sort select="ARTIST"/>
...


I believe the default value for the data-type attribute is "text" which is prolly what you want.



Todd Ditchendorf
Software Engineer



On Jan 1, 2007, at 6:00 PM, Mark Spidle wrote:

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


Mark Spidle
Assistant Manager of Information Systems
515-457-5873


 _______________________________________________
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: 
 >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.