Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 14th, 2005, 04:39 PM
Banned
Points: 1,561, Level: 16
Points: 1,561, Level: 16 Points: 1,561, Level: 16 Points: 1,561, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2005
Location: , , .
Posts: 317
Thanks: 0
Thanked 0 Times in 0 Posts
Default xsl:sort Question

I'm using the transformNode method to convert an XML doc and an XSL stylesheet to XHTML using an ASP.NET/VB.NET script, and it works great. But when I try to add an <xsl:sort... property to the xsl stylesheet, I get the following error message:
Server Error in '/' Application.
Keyword xsl:sort may not be used here.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Runtime.InteropServices.COMException: Keyword xsl:sort may not be used here.

Source Error:
Line 18:
Line 19: 'Transform file
Line 20: Response.Write(xml.transformNode(xsl))
Line 21: %>
Source File: c:\inetpub\wwwroot\DIRECTORY\FILENAME.aspx Line: 20

I'm a complete newbie to XML and XSL/XSLT, so I'm not sure why I'm receiving this message. So my question is:
Is it not possible to use the <xsl:sort... method when using the transformNode method?

Thanks for any & all help.

P.S. Here's the code that I'm using in case it needs to be referenced:

XML doc:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<formsdocs>
    <form>
        <title>FORM TITLE</title>
        <url>http://DOMAIN/DIRECTORY/FORMNAME.pdf</url>
        <format>pdf</format>
        <target>_blank</target>
        <type>internal</type>
        <size>3053 KB</size>
        <dept>DEPT</dept>
        <div />
    </form>
</formsdocs>
XSL stylesheet:
Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
        <html xmlns="http://www.w3.org/1999/xhtml">
            <head>
                <title>PAGETITLE</title>
            </head>
            <body>
                <h1>PAGE HEADER</h1>
                <table class="navyblueborder">
                    <tr bgcolor="#333366" class="whiteheader">
                        <th align="left">Title</th>
                        <th align="left">Format</th>
                        <th align="left">Type</th>
                        <th align="left">Size</th>
                        <th align="left">Dept</th>
                    </tr>
                    <xsl:for-each select="formsdocs/form">
                        <tr>
                            <td><a href="{url}" target="{target}"><xsl:value-of select="title" /></a></td>
                            <td><xsl:value-of select="format" /></td>
                            <td><xsl:value-of select="type" /></td>
                            <td><xsl:value-of select="size" /></td>
                            <td><xsl:value-of select="dept" />
                            <xsl:choose>
                                <xsl:when test="div = ''">
                                </xsl:when>
                                <xsl:otherwise>
                                    (<xsl:value-of select="div" /> Division)
                                </xsl:otherwise>
                            </xsl:choose>
                            </td>
                        </tr>
                    </xsl:for-each>
                </table>
            </body>
        </html>
    </xsl:template>
</xsl:stylesheet>
ASP.NET/VB.NET script:
[code]<%@ Page Language="VB" ContentType="text/html" ResponseEncoding="iso-8859-1" Debug="true" %>
<%@ import Namespace="System.Data" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%
'Load XML
Dim xml = Server.CreateObject("Microsoft.XMLDOM")
xml.async = false
xml.load("http://DOMAIN/DIRECTORY/XMLFILE.xml")

'Load XSL
Dim xsl = Server.CreateObject("Microsoft.XMLDOM")
xsl.async = false
xsl.load("http://DOMAIN/DIRECTORY/XSLFILE.xsl")

'Transform file
Response.Write(xml.transformNode(xsl))
%>
Code:

KWilliams
Reply With Quote
  #2 (permalink)  
Old July 14th, 2005, 04:48 PM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You said:

But when I try to add an <xsl:sort... property to the xsl stylesheet, I get the following error message:
Server Error in '/' Application.
Keyword xsl:sort may not be used here.

This message means you have added xsl:sort in the wrong place.

Since you haven't told us where you added it, it's hard to tell you any more than the error message already says.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
  #3 (permalink)  
Old July 14th, 2005, 04:57 PM
Banned
Points: 1,561, Level: 16
Points: 1,561, Level: 16 Points: 1,561, Level: 16 Points: 1,561, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2005
Location: , , .
Posts: 317
Thanks: 0
Thanked 0 Times in 0 Posts
Default

...sorry about that. This is where I added the sort method:

<xsl:choose>
 <xsl:when test="div != ''">
  (<xsl:sort select="div" /> Division)
 </xsl:when>
</xsl:choose>

...which I think should work. It's a pretty simple setup, and it's correct from everything that I've read about it. But if you see what I'm doing wrong, please let me know.

Also, I tried to "<>" or "#60;#62;" instead of "!=", but I get this error message:
Expression expected. div <-->><-- ''

Thanks.

KWilliams
Reply With Quote
  #4 (permalink)  
Old July 14th, 2005, 05:45 PM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

xsl:sort has to be a child of xsl:for-each or xsl:apply-templates. These are the two instructions that iterate over a node-set, and xsl:sort says in what order the nodes in the node-set are processed. Not only can't you use it like this:

<xsl:choose>
 <xsl:when test="div != ''">
  (<xsl:sort select="div" /> Division)
 </xsl:when>
</xsl:choose>

but I have no idea what you imagine it might mean.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
  #5 (permalink)  
Old July 15th, 2005, 08:11 AM
Banned
Points: 1,561, Level: 16
Points: 1,561, Level: 16 Points: 1,561, Level: 16 Points: 1,561, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2005
Location: , , .
Posts: 317
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok, I would ask how you might go about doing that, but you don't seem like you're in the mood to answer my question anyway. So don't worry about it.

KWilliams
Reply With Quote
  #6 (permalink)  
Old July 16th, 2005, 10:01 PM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

If you can tell us what you want to achieve then we can try and help you achieve it. So far, I don't know what you are trying to do. Your code is incorrect, but I can't correct it for you because I don't know what you thought it might do. I think the fact that I'm replying at all is evidence enough that I'm trying to help.

I've just noticed this remark of yours:

>Also, I tried to "<>" or "#60;#62;" instead of "!="

This is really a bit worrying. It suggests you're trying to work by trial and error. This is not a good way forward. There are specs, books, and tutorials to teach the language that suit every possible taste. They will all tell you that the XPath "not-equals" operator is "!=".


Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
  #7 (permalink)  
Old July 18th, 2005, 08:39 AM
Banned
Points: 1,561, Level: 16
Points: 1,561, Level: 16 Points: 1,561, Level: 16 Points: 1,561, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2005
Location: , , .
Posts: 317
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:If you can tell us what you want to achieve then we can try and help you achieve it. So far, I don't know what you are trying to do. Your code is incorrect, but I can't correct it for you because I don't know what you thought it might do. I think the fact that I'm replying at all is evidence enough that I'm trying to help.
I appreciate you responding to my post, but I thought that I was pretty clear in posing my question "Is it not possible to use the <xsl:sort... method when using the transformNode method?". I thought that this question would only have a yes or no answer, but I understand now that the answer to my question is "Yes it is possible, if it's done correctly".

Quote:
quote:I've just noticed this remark of yours:

>Also, I tried to "<>" or "#60;#62;" instead of "!="

This is really a bit worrying. It suggests you're trying to work by trial and error. This is not a good way forward. There are specs, books, and tutorials to teach the language that suit every possible taste. They will all tell you that the XPath "not-equals" operator is "!=".
As I stated in my original post, "I'm a complete newbie to XML and XSL/XSLT". I am learning as I'm going along, since I've not received any training on these languages. I have found several tutorials on XML and XSLT, but I've found that almost all of these so-called tutorials are basically copied & pasted from an original tutorial. Which is not a great help if you have a question that's outside of that tutorial's realm. Concerning the "trial & error" method of development, I would think that most developers without resources such as training will try their best to create correct code the first time. But if I ever meet a developer (except for an expert developer) that reviews some code online, and is able to reproduce that code without any issues arrising, then I will be in shock. I agree that it's best to do correct code, but if errors weren't meant to come up for developers, I don't believe that they would have created error messages for those same developers to troubleshoot/debug their code. But that's my own opinion. Please Note: My pages are located on a test-server internally, so they're of course not live for users to view.

Before your similar post that contained an answer, I had received this answer to my original question through another forum:
"<xsl:sort> can only be the child of <xsl:for-each> or <xsl:apply-templates>, for example:

Code:
<xsl:for-each select="formsdocs/form"> <xsl:sort select="div" /> ... etc. ... </xsl:for-each> <xsl:apply-templates select="formsdocs/form"> <xsl:sort select="div" /> </xsl:apply-templates>
Make sure that the sort instruction is the first instruction after the opening <xsl:for-each ... >.

If <div> is empty (in the XML) then it won't effect the sort anyway so you don't really need to instruct the XSLT to sort by it only if it's not empty."[quote]

So I've changed my code to reflect this correction, and it works fine. I'm now working on making that same xsl:sort method dynamic with the use of the xsl:param method, and it's going well so far. But thanks again for your reply, and I hope that you have a great week.

KWilliams

KWilliams
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need Xsl to Sort the following simple xml: Takashi321 XSLT 3 August 27th, 2007 11:54 AM
Unable to sort using xsl sort command sly_jimmy_boy XSLT 3 June 17th, 2005 05:15 AM
XSLT-- xsl:sort help... debo XSLT 2 December 3rd, 2004 04:25 PM
xsl:sort and IE 5.0 Issue babloo81 XSLT 1 March 17th, 2004 06:12 AM
xsl:sort- select attribute, syntax question Flashlight XSLT 3 August 14th, 2003 12:27 AM



All times are GMT -4. The time now is 03:55 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.