Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
| 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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old April 21st, 2006, 01:23 PM
Registered User
 
Join Date: Apr 2006
Location: , , United Kingdom.
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Writing works then reading fails

Hi people, I could really use your help if you've ever tried using asp to do multiple xml->xml transormations using xsl.

My problem is that I wish to sort a list of tags by date using xsl, save them to a file and then to do further transformations on that new file using xsl.

The issue is that the sorted file simply can't be read by xsl properly.

After hours of trying to play with character encodings etc I have worked out that:

1. If the same text that is output is written by notepad (typed by hand) (instead of asp) new xsl transformations *do* work

2. Asp seemingly can read in a range of formats including UTF-16 and ISO-8859-1, and mix them too (different xsl encoding to xml encoding to output encoding)

a point to mention is I'm using the XMLDOM save method to save the file, but I've tried serialising it to a text file and using the newer MS2XML.Template way and everything has the same problem.

  #2 (permalink)  
Old April 21st, 2006, 08:50 PM
Registered User
 
Join Date: Apr 2006
Location: , , United Kingdom.
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok, so I tried to just use firefox's output, save it to a file (paste,notepad,save) and then see if that worked, but it failed,

below is the source and procedure:

formatList.xml


<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet href="testsort.xsl" type="text/xsl"?>
<shows>
   <showdef date="20060420" href="format_archive/20060420.xml">format 1</showdef>
  <showdef date="20060410" href="format_archive/20060410.xml">format 2</showdef>
  <showdef date="20060415" href="format_archive/20060415.xml">format 3</showdef>

</shows>


Next the testsort.xsl

<?xml version="1.0" encoding="ISO-8859-1"?>

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output encoding="ISO-8859-1" omit-xml-declaration="no"/>
<xsl:template match="/">
<show>
<xsl:for-each select="shows/showdef">
<xsl:sort select="@date" order="descending"/>
<xsl:copy-of select="."/>
</xsl:for-each>
</show>

</xsl:template>

</xsl:stylesheet>


The output I get is this: (results.xml)

<show>
<showdef date="20060420" href="format_archive/20060420.xml">format 1</showdef>
<showdef date="20060415" href="format_archive/20060415.xml">format 3</showdef>
<showdef date="20060410" href="format_archive/20060410.xml">format 2</showdef>
</show>


But if I add a stylesheet to this with this tag at the top:
<?xml-stylesheet href="testsort.xsl" type="text/xsl"?>

(the same testsort.xsl for testing purposes) I don't get sorted output as before, I just get:

<shows/>

How can this be the case when the only difference between the original formatList.xml and the results.xml is the order of the showdef tags [and maybe the character encoding??]

Any help is hugely appreciated

ben

  #3 (permalink)  
Old April 21st, 2006, 09:11 PM
Registered User
 
Join Date: Apr 2006
Location: , , United Kingdom.
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

ok so I realised that there was a descrepancy between the Shows and show tags, its fixed now...just wish there was a better way to debug xpaths that can't be matched

  #4 (permalink)  
Old April 22nd, 2006, 04:09 AM
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

>just wish there was a better way to debug xpaths that can't be matched

First: don't try to use the browser as a development environment. It's the worst possible environment for debugging. Use Stylus Studio or XML Spy, or just a text editor and command line XSLT processor such as Saxon.

Second: The advanced solution is to use schema-aware transformations with XSLT 2.0. See http://www.stylusstudio.com/schema_aware.html - the idea here is that if the XSLT processor knows about the schema for your source document, then it can detect invalid paths at compile time.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference


Similar Threads
Thread Thread Starter Forum Replies Last Post
Shopping Cart works on Local Sys, but fails on IIS IronSights ASP.NET 2.0 Basics 0 July 27th, 2006 09:52 AM
Javscript works well in aspx page but fails... vivek_inos ASP.NET 1.0 and 1.1 Professional 2 June 18th, 2006 11:26 PM
.ASP login page fails offline, but works online ?? putte74 Classic ASP Basics 1 January 10th, 2006 07:21 PM
PHP code - works in Firefox, fails in IE gingerbraid Beginning PHP 13 October 6th, 2005 06:33 PM
Reading and Writing Objects Capi JSP Basics 2 July 29th, 2003 03:26 PM





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