Subject: RE: [xsl] debugging techniques [was:qualitative decline of xsl-list questions] From: "Passin, Tom" <tpassin@xxxxxxxxxxxx> Date: Wed, 4 Dec 2002 12:01:44 -0500 |
To add to Mike Kay's selection - - If any xpath expression is not doing what you expect, turn it into a variable and display its value. Use the variable wherever you used the original expression. - If you want to try out a variation of a variable, template, etc., just copy it and change the name of one of the copies. For example - <!-- this was the original version - it will be ignored --> <xsl:template match='xroot'> <!-- some tricky stuff here --> </xsl:template> <xsl:template match='root'> <!-- some different tricky stuff here --> </xsl:template> - Do not fear to add all kinds of elements temporarily to the output, just to display information. Never mind that you do not want them in the end result. You can always remove them or use Mike's debug: technique to suppress them. This is just like adding print() statements in other languages, and it is just as helpful. - Start out simple, especially when you want html output. The html overhead structures often obscure what is really happening. For example, if you want to group data into a table, first generate a simple list and get it grouped the way you want. Then you can add the html table elements. This is sort of an XP approach - start with the simplest thing that can possibly work, then build up to what you really want. This tip has probably been the most helpful one for me. - Use variables liberally and name them with helpful names (even if they are long). - If you use position() and you get unexpected results, (temporarily) display the value of position() so you do not have to guess what it is returning. - If you get unexpected results and cannot understand them, try another processor. Once in a while esoteric points get handled a different way by another processor. Seeing any difference may clear up your understanding, and if there really is a bug you want to find out. - Once you get things working, see where you can simplify, if only to help you understand the code later. If you cannot get it working, simplify so that you can be sure of the part that does not work. - Use copy-of to display the chunk of the source that you really are working with - it may not be what you expected. - If you cannot figure out how to "loop" through some elements - especially if you cannot figure out where to start and stop - you almost certainly need to change how you look at the problem. Almost always, you need to figure out how to select the right set of nodes, then operate on these nodes (probably with apply-templates) rather than trying to "loop". - If all else fails, consider a two-pass approach. - Try hard to avoid using any processor-specific extensions. The effort to understand your problem and xslt well enough to avoid using them will pay off even if in the end you do have to fall back on such extensions. Cheers, Tom P XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] debugging techniques [was, "Braumüller, Hans" | Thread | Re: [xsl] debugging techniques [was, Jeff Kenton |
RE: [xsl] Problem using translate t, El Hage Camille | Date | RE: [xsl] a*b, sum(c*d), sorted on , McNally, David |
Month |