Solved

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

Posted on 2003-10-24
6
448 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
  • 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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

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…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

708 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now