?
Solved

Error message - xsl:apply-templates may not contain xsl:sort

Posted on 2003-10-24
6
Medium Priority
?
467 Views
Last Modified: 2010-05-18
I get the above error message in my code and I am looking to see if someone can help me out.

Here is what I am trying to do:

I have an XSL file - sort.xsl and it has the following data:

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
      <xsl:template match="RecordSet">
      <xsl:apply-templates select="Record">
      <xsl:sort select="DESC" />
      <xsl:sort select="NUMBER" />
      </xsl:apply-templates>      
      </xsl:template>
</xsl:stylesheet>


I have an xml file that I need sorted. Test.xml
<RecordSet>
      <Record rownum="1">
            <DESC>Good Product</DESC>
            <NUMBER>123</NUMBER>
            <QUANTITY>5</QUANTITY>
      </Record>
      <Record rownum="2">
            <DESC>Very Bad Product</DESC>
            <NUMBER>123A</NUMBER>
            <QUANTITY>5</QUANTITY>
      </Record>
      <Record rownum="2">
            <DESC>Very Good Product</DESC>
            <NUMBER>ABC</NUMBER>
            <QUANTITY>5</QUANTITY>
      </Record>
      <Record rownum="1">
            <DESC>Bad Product</DESC>
            <NUMBER>123SDA</NUMBER>
            <QUANTITY>5</QUANTITY>
      </Record>
      <Record rownum="2">
            <DESC>Very Bad Product</DESC>
            <NUMBER>123</NUMBER>
            <QUANTITY>5</QUANTITY>
      </Record>
      <Record rownum="2">
            <DESC>Very Bad Product</DESC>
            <NUMBER>123</NUMBER>
            <QUANTITY>5</QUANTITY>
      </Record>
<RecordSet>


I need to do this in an ASP page. This is part of a huge ASP page, so I am pasting only the pertinent information here.

Set objXML = Server.CreateObject ("MSXML2.DOMDocument.3.0")
Set objSortXSL = Server.CreateObject ("MSXML2.DOMDocument.3.0")

If Not objSortXSL.load(server.MapPath("Sort.xsl")) then
         Response.Write "Problems"
         Response.end
End If

Response.write objPC2XML.transformNode(objSortXSL)

Upon execution I get the following error message while trying to transform the node.

Error Type:
msxml3.dll (0x80004005)
Keyword xsl:apply-templates may not contain xsl:sort.

I have MSXML3 version SP3 installed in side by side mode with V2.

If someone can help that would be great. Thanks.

Hari.



0
Comment
Question by:StuckOnceAgain
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 7

Expert Comment

by:Brad Dobyns, CSM
ID: 9617579
Well, you'll need to do away with Version 2 because XSLT isn't supported with MSXML2. If you're doing client-side transformation in Internet Explorer, you need MSXML3 installed in replace mode. Try reading the MSXML FAQ at
http://www.netcrucible.com/xslt/msxml-faq.htm.

Brad
0
 

Author Comment

by:StuckOnceAgain
ID: 9617667
I am not using V2. I Explicitly call out V3 with

CreateObject ("MSXML2.DOMDocument.3.0")

Also, I am trying the transformation on the server side and not on the clinet side.
0
 
LVL 7

Expert Comment

by:Brad Dobyns, CSM
ID: 9617779
OK. Well, I think you need to take out the select attribute for the apply-templates statement. That might help as I don't think I've seen that in any of the XML I've seen:

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
     <xsl:template match="RecordSet">
          <xsl:apply-templates>
               <xsl:sort select="DESC" />
               <xsl:sort select="NUMBER" />
          </xsl:apply-templates>    
     </xsl:template>
</xsl:stylesheet>

Brad
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 7

Expert Comment

by:Brad Dobyns, CSM
ID: 9617797
I've seen the select attribute used this way:

<xsl:template match="Record">
    Description:  <xsl:apply-templates select="DESC"/>
    Number:  <xsl:apply-templates select="NUMBER"/>
    Quantity:  <xsl:apply-templates select="QUANTITY"/>
    <xsl:text></xsl:text>
</xsl:template>

Does that help?

Brad
0
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 400 total points
ID: 9617864
There are a number of problems here:
1. I suspect that this is a typo but your XML sample is not well-formed.
2. The old namespace: "http://www.w3.org/TR/WD-xsl" is not supported in v4 (and yes I realize you are still using v3).

If I use v3 with your XSL I can duplicate your problem, if on the other hand I use the newer namespace I do not get the error you report. As in:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      <xsl:template match="RecordSet">
            <xsl:apply-templates select="Record">
                  <xsl:sort select="DESC" />
                  <xsl:sort select="NUMBER" />
            </xsl:apply-templates>
      </xsl:template>
</xsl:stylesheet>

I get the same result with both v3 and v4:
<?xml version="1.0" encoding="UTF-16"?>Bad Product123SDA5Good Product1235Very Bad Product1235Very Bad Product1235Very Bad Product123A5Very Good ProductABC5

Anthony
0
 

Author Comment

by:StuckOnceAgain
ID: 9617933
acperkins, U THE MAN!!!!!!!!!!!!!!!

duh, i can't believe that i used the old namespace. Yup that did the trick.

Yea the xml not being well formed was a typo. But the namespace wasnt.

Thanks a bunch.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question