Subject: Re: [xsl] xpath query From: "Sean Tiley" <sean.tiley@xxxxxxxxx> Date: Sun, 20 Jan 2008 15:01:53 -0500 |
That helps alot. Thank you Sean On Jan 20, 2008 11:05 AM, Colin Paul Adams <colin@xxxxxxxxxxxxxxxxxx> wrote: > >>>>> "Sean" == Sean Tiley <sean.tiley@xxxxxxxxx> writes: > > Sean> I guess fundamentally I do not understand how the processor > Sean> applies the stylesheet templates to the xml document. > > Sean> Say I have the followng XML > > Sean> <root> <file name="test.java"> <error line="4" > Sean> message="Message1" severity="2"/> <error line="67" > Sean> message="Message2" severity="4"/> </file> <file > Sean> name="code.java"> <error line="2" message="Message1" > Sean> severity="2"/> <error line="54" message="Message2" > Sean> severity="4"/> <error line="122" message="Message1" > Sean> severity="2"/> </file> </root> > > Sean> Then as the processor processes the tree for this xml file, > Sean> it finds the <root> element, then looks for a template that > Sean> matches it. It would find the identity template and invoke > Sean> this template. At this point, what does it put out to the > Sean> result tree if anything? > > > A recap of what the identity template looks like. here is one form. > > <xsl:template match="@* | node()"> > <xsl:copy> > <xsl:apply-templates select="@* | node()"/> > </xsl:copy> > </xsl:template> > > If this is the template that proves to be the best match for your > element named root, then the processor will perform an xsl:copy of > that element. > > From the XSLT 2.0 recommendation: > > "The xsl:copy instruction provides a way of copying the context > item. If the context item is a node, evaluating the xsl:copy > instruction constructs a copy of the context node, and the result of > the xsl:copy instruction is this newly constructed node. By default, > the namespace nodes of the context node are automatically copied as > well, but the attributes and children of the node are not > automatically copied." > > So the processor will notionally now create an empty > <root> > > </root> > > element in the result tree. > It then looks at the body of the xsl:copy instruction, to see what > else it has to do. > > In this case, it is instructed to apply templates that match all the > elements attributes and child nodes. > > In this case there are no attributes, but we do have some element > children (there may also be white-space text nodes, depending on > whether or not they have been stripped - let's assume none for the > moment). > > The first element child it finds is the element: > > <file name="test.java"> > > So it will then try to find a template that matches this node. If you > don't have any more specific templates to match this, then the > identity template will match it. > > So it will copy it (execute the xsl:copy instruction in the > template). > Now the result tree looks like: > > <root> > <find> > </find> > </root> > > At which point it will try to execute the body of the xsl:copy > again. This time it finds and attribute node (name="test.java"), so it > will try to match that. Again, if you have no more specific template > than the identity template, the identity template will match. So the > processor will execute the xsl:copy instruction in the template, and > the result tree will now look like this: > > <root> > <find name="test.java"> > </find> > </root> > > At which point it will try to execute the body of the xsl:copy > again. This time it finds no attributes or child nodes (an attribute > node has no children or attribtes), so it finishes that invocation of > the identity template, and resumes on the previous one where it left > off (matching the attribute name in the find element). It will > discover that find has no more attributes or child nodes, so it will > finish exceuting that invocation of the identity template too, and > resumes on the previous one where it left off (matching the find child > of the root element). It will look for further children of the root > element, and will find the first error element, so it will attempt to match > that. > > Again, if you have no more specific template > than the identity template, the identity template will match. Etc. etc. > -- > Colin Adams > Preston Lancashire > > -- Sean Tiley sean.tiley@xxxxxxxxx
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] xpath query, Colin Paul Adams | Thread | Re: [xsl] xpath query, Abel Braaksma |
Re: [xsl] xpath query, Colin Paul Adams | Date | [xsl] The identity transform and at, Andrew Welch |
Month |