Solved

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

Posted on 2003-10-24
6
462 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
Industry Leaders: 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

685 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