Solved

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

Posted on 2003-10-24
6
464 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
Technology Partners: 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 100 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
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…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

724 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