Subject: Re: [xsl] XSLT Processing Model Questions From: Peter Davis <pdavis152@xxxxxxxxx> Date: Sun, 14 Apr 2002 19:21:17 -0700 |
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Sunday 14 April 2002 21:54, Dietrich Ayala wrote: > But looking > at the example, I cannot understand what logic a processor is using to > determine the location in the result tree at which it appends new nodes. It just does it in the order that it matches the templates. For example: [source] <root> <e1/> <e2> <e3/> </e2> <e3/> </root> [xsl] <xsl:template match="root"> <body> <xsl:apply-templates/> </body> </xsl:template> <xsl:template match="e1"> matched e1 </xsl:template> <xsl:template match="e2"> matched e2 <xsl:apply-templates/> end of e2 </xsl:template> <xsl:template match="root/e3"> matched e3 </xsl:template> <xsl:template match="e2/e3"> matched e3 child of e2 </xsl:template> [output] matched e1 matched e2 matched e3 child of e2 end of e2 matched e3 It just appends the results as it goes, and most of the times this means that it processes the source nodes in document order (unless you change this with a special apply-templates or xsl:sort). * The "root" template does an apply-templates and selects "e1, e2, e3", in order. * The processor finds templates to match those nodes, in order. So it executes the "e1", "e2", and "root/e3" templates in order. * But the "e2" template does some more work, namely doing another apply-templates, and so this happens before the "root/e3" template is executed. So in the "e2" template, it selects another "e3" (the only child), and the template that matches that is "e2/e3". So the whole process goes like this: execute "root" template select "e1, e2, e3" children of "root" execute "e1" template output "matched e1" execute "e2" template output "matched e2" select "e3" child of "e2" execute "e2/e3" template output "matched e3 child of e2" output "end of e2" execute "root/e3" template output "matched e3" done Hope that helps. It's really pretty simple; there isn't a whole lot of "magic" going on, it just does things in the order that you tell them to. The biggest mixup probably is the difference between this example and what happens when the result tree has parent and child elements. Well, there is no difference. Think of this example: <xsl:template match="foo"> <bar> <xsl:apply-templates/> </bar> </xsl:template> as having three instructions: "start <bar>", "apply-templates" (and execution of the matched templates), and "end <bar>". Again, this all happens in this exact order. Everything that is output after "start <bar>" and before "end <bar>" just ends up as a child of <bar> in the result tree. If you're still confused, use your processors "trace" functionality. For example: * in Xalan, use one or more of the -TT, -TG, -TS, and -TTC options when running "java org.apache.xalan.xslt.Process". See http://xml.apache.org/xalan-j/commandline.html for more info. * in Saxon, use the -T option when running "java com.icl.saxon.StyleSheet". I haven't tried to do this with other processors. These options will make the processor output exactly what it is doing at each step of the transformation; hopefully you can think up some examples and watch exactly what happens if you still have questions. - -- Peter Davis -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.6 (GNU/Linux) Comment: For info see http://www.gnupg.org iD8DBQE8ujkgNSZCJx7tYycRApLGAJ0dGS+mbm6pjETHvr11KGs0/t5xnACgmRY9 OAlnr/wcWp9DO3TyzwHLJ8o= =QnWL -----END PGP SIGNATURE----- XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] XSLT Processing Model Que, Dietrich Ayala | Thread | Re: [xsl] XSLT Processing Model Que, David Carlisle |
RE: [xsl] XSLT Processing Model Que, Dietrich Ayala | Date | RE: [xsl] XSLT Processing Model Que, Dietrich Ayala |
Month |