xsl:apply-templates dont get it

Hey

I think i've figured out the idea behind apply-templates. But going
through the tutorial on
<http://www.w3schools.com/xsl/xsl_apply_templates.asp> theres simply
just something that i dont get! In the following i've copy pasted the
example from <http://www.w3schools.com/xsl/xsl_apply_templates.asp>
into this post. I divide into sections and my real question will come
after the code snippet:

Section 1:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!--  Edited with XML Spy v4.2 -->
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

Section 2:
 <xsl:template match="/">
   <html>
     <body>
       <h2>My CD Collection</h2>
       <xsl:apply-templates />
     </body>
   </html>
 </xsl:template>

Section 3:
 <xsl:template match="cd">
   <p>
      <xsl:apply-templates select="title" />
      <xsl:apply-templates select="artist" />
   </p>
 </xsl:template>

Section 4:
 <xsl:template match="title">
   Title:
   <span style="color:#ff0000">
     <xsl:value-of select="." />
   </span>
   <br />
 </xsl:template>

Section 5:
 <xsl:template match="artist">
   Artist:
  <span style="color:#00ff00">
    <xsl:value-of select="." />
  </span>
  <br />
 </xsl:template>

Last Section:
</xsl:stylesheet>

Ok. Now here comes what puzzles me:
You can use the apply-templates to tell the parser that it must apply
templates at the specifik point where you set the apply-templates
"tag". Now what this code does is, it comes to the apply-templates in
section 2, it runs the template in section 3, wich runs Section 4 and
5. Actually Section 2 only runs section 3, and this is what puzzles me.
I would expect the apply-templates in section 2 to run section 3, wich
runs section 4 and 5, and then after that i would expect it to move on
to section 4 and 5, before going on ie. it has to run section 4 and 5 2
times total, but only rund this 1 time. Why?

As of now it makes no sense to me... Hope that theres a person more
clever than me that can enlighten me at this specific question?


Regards Jimmy

0
jimbo_vr5 (6)
11/4/2005 8:11:19 AM
dotnet.xml 7266 articles. 0 followers. Follow

2 Replies
786 Views

Similar Articles

[PageSpeed] 7


jimbo_vr5@hotmail.com wrote:


> Section 2:
>  <xsl:template match="/">
>    <html>
>      <body>
>        <h2>My CD Collection</h2>
>        <xsl:apply-templates />
>      </body>
>    </html>
>  </xsl:template>

> You can use the apply-templates to tell the parser that it must apply
> templates at the specifik point where you set the apply-templates
> "tag". Now what this code does is, it comes to the apply-templates in
> section 2, it runs the template in section 3, wich runs Section 4 and
> 5. Actually Section 2 only runs section 3, and this is what puzzles me.
> I would expect the apply-templates in section 2 to run section 3, wich
> runs section 4 and 5, and then after that i would expect it to move on
> to section 4 and 5, before going on ie. it has to run section 4 and 5 2
> times total, but only rund this 1 time. Why?

Please not that there is an xsl group on this server so any xsl specific 
stuff should be asked/discussed there. This is dotnet.xml so .NET and 
XML specific stuff should go here.

As for xsl:apply-templates, it is defined here:
   <http://www.w3.org/TR/xslt#section-Applying-Template-Rules>
There is says:
   "In the absence of a select attribute, the xsl:apply-templates 
instruction processes all of the children of the current node"
In your "section 2" snippet there is no select attribute on the 
xsl:apply-templates so all children of the current node are processed, 
where the current node is the root node / (as that is the template we 
are in).

You haven't provided the input XML but assuming it is this 
<http://www.w3schools.com/xsl/cdcatalog.xml> then the root node / has 
two child nodes, a comment node and an element node, the root element 
catalog.

Now the processor looks for matching templates for those child nodes, 
the stylesheet itself does not have any (there is no template for 
comment nodes and none for a catalog element) but there are built-in 
template rules (<http://www.w3.org/TR/xslt#built-in-rule>) which are 
then applied here, the built-in template rule for comment nodes does 
nothing, but the built-in template rule for element nodes recursively 
processes the child nodes of an element so the child nodes of the 
catalog element are processed next. So that way the processor then 
applies the template for cd elements.


-- 

	Martin Honnen --- MVP XML
	http://JavaScript.FAQTs.com/
0
mahotrash (1777)
11/4/2005 1:22:51 PM
jimbo_vr5@hotmail.com wrote:
[snip]
> Ok. Now here comes what puzzles me:
> You can use the apply-templates to tell the parser that it must apply
> templates at the specifik point where you set the apply-templates
> "tag". Now what this code does is, it comes to the apply-templates in
> section 2, it runs the template in section 3, wich runs Section 4 and
> 5. Actually Section 2 only runs section 3, and this is what puzzles
> me. I would expect the apply-templates in section 2 to run section 3,
> wich runs section 4 and 5, and then after that i would expect it to
> move on to section 4 and 5, before going on ie. it has to run section
> 4 and 5 2 times total, but only rund this 1 time. Why?

XSLT is declarative, not procedural. The order in which you give the
templates is irrelevant. Each template is simply a statement or rule
for what must happen if and when the matched element type is found:
the order in which they get used is determined by the order in which
the element types occur in your document, unless your templates 
explicitly state that some elements must be processed out of order.

///Peter
-- 
XML FAQ: http://xml.silmaril.ie/

0
Peter
11/6/2005 11:24:15 PM
Reply:

Similar Artilces:

where to get WinXp SP2 for one computer
Hi I need a copy or download link for WinXP SP2 for a single machine 32 bit version. I'm just updating my wife's Win XP home edition SP1 laptop. but Microsoft update site just links to SP3 or SP2 for multiple machines? I believe i can order a free hard copy online from microsoft, but I'd rather just DL one. I did try a link from another site which let me DL it but I noticed the KB number applied to the multiple machine SP2. Thanks -- Regards p.mc Use the link you saw. It will give you what you want. "p.mc" <p.mc@home.com> wrote in ...

How do I get my Outlook booking shown correctly in Groupwise?
My Outlook calender bookings comes out all garbled in Groupwise. I think it has something to do with a "Mime" format. What should I do to correct this? "Johan Schoombee" <Johan Schoombee@discussions.microsoft.com> wrote in message news:2C675176-660A-4F4F-AF10-B9015B5418E7@microsoft.com... > My Outlook calender bookings comes out all garbled in Groupwise. I think it > has something to do with a "Mime" format. What should I do to correct this? Try sending them in iCalendar format. Create the meeting, then click Action>Forward as iCa...

Column not getting updated
Hi Guy, Trigger below is not updating ODS_INST_ID column as it should when new row is inserted. This behavior happens when new row is a copy of existing row i.e. source row already has data in ODS_INST_ID. So for example if source row has ODS_INST_ID = 1, copied row should have ODS_INST_ID = 2 but I see ODS_INST_ID = 1. Data is getting copied in a table by an application. Strangely, if 4 rows are to be copied, trigger works only for 1 row. Any idea what may wrong with the trigger below? Thanks, Usman USE [UK8] GO /****** Object: Trigger [dbo].[EQUIP_ods_inst_id_trig] ...

GAL does not get updated at all
I have exchange 2003 enterprise running in mixed mode on Windows 2003. My Active Directory servers are running on Windows 2000 server. My problem is that the users in the AC are not replicated to the GAL (or any other address lists). Consequently, nobody can log in via Outlook and I cannot set the sharing of certain public folders. (the users can log on via Outlook Web Access). Running the preview on the properties of the GAL gives the correct addresses. So it seems to be an RUS problem. RUS Rebuilding, updating, or restarting of server does not help. I have checked all issues in Microsoft...

How do you get rid of a formula imbedded in a linked sheet
I have a workbook that was e-mailed to me. When I format or change one worksheet, it makes the same changes on another worksheet within the workbook. How can I get rid of this? ...

instructor's solutions manual for Applied Calculus for the Managerial, Life, and Social Sciences, 7 E, by Soo T. Tan
I have solutions manuals for these scientific textbooks .. They are all in PDF format .. If you are interested in any one, simply send me an email to macmorino(at)gmail(dot)com .. Please this service is NOT free. Here are some .. A First Course in Differential Equations (7th ed.) Zill & Diferential Equations (5th ed.)Zill & Cullen A Course in Game Theory by Osborne, Rubinstein A Course in Modern Mathematical Physics by Peter Szekeres A First Course in Abstract Algebra (7th Ed., John B. Fraleigh) A First Course in Differential Equations - The Classic Fifth Edition B...

Getting Chart Point info
Hi - I am building a "drill down" chart. When you click on one of the points of the chart, it takes you to anohter chart based on the informaiton on the point. I am using the MouseUp event and I have the Arg1 and Arg2 data. What I don't have is the actual "name" of the point. If you mouse over the point it will tell you the "name" of the series and the "name" of the point. How do I get this "name"? Arg2 simply tells me which point (1,2,3,4 etc.) in the series. I need the name. thanks Lizzard ...

Getting rid of empty cells
I have a column with values in cells A1, A2, A3, A7, A8, A9. Is there a way to have the values in cells A7, A8, A9 move to cells A4, A5, A6 with cutting and pasting. I have a lot of values and empty cells so if there is a formula that would be a lot quicker than cutting and pasting. Thanks. If the rest of the row is empty, why not just sort by blanks and delete en masse? -- Don Guillett SalesAid Software donaldb@281.com "Jambruins" <Jambruins@discussions.microsoft.com> wrote in message news:28628FAA-C4A1-4BC2-9228-94E917373FDC@microsoft.com... > I have a column with...

How get values onto X-axis?
I'm using Excel 2003 to make a chart of my blood pressure readings. The readings are taken every 30 minutes for a 24 hour period. It may sound basic but I can't get the X-axis to show the time of day. Can someone tell me how to do this please. This is my XLS file: http://www.datafilehost.com/download-c5309ef4.html Hi Juniper Is this what you want, see link attached. http://www.datafilehost.com/download-942bb90e.html HTH John "juniper" <invalid@nospaml.com> wrote in message news:Xns9D47ED3312E3F5D4AM2@unknown.sj.astraweb.com... > I'm using...

Getting cd copies of software
Operating System: Mac OS X 10.5 (Leopard) Processor: Intel After I complete my 30 free trail of Microsoft Office for Mac, can I get a cd copy of the program or am I stuck with just the downloaded copy? If I do purchase a CD copy after the trial period will the work I did on the trial product transfer to the program when I install it from disk? On 5/4/09 9:49 AM, "lgiamette@officeformac.com" <lgiamette@officeformac.com> wrote: > After I complete my 30 free trail of Microsoft Office for Mac, can I get a cd > copy of the program or am I stuck with just the downloaded cop...

How to get intermediate values from smooth graph in Excel ?
For example: x y 1 5.5 2 8.5 3 10.5 4 11.5 For x=1.56, what will be the corresponding value of y from drawn graph ? Check this post in the archives: http://www.mcse.ms/archive144-2004-1-346324.html - Jon ------- Jon Peltier, Microsoft Excel MVP Peltier Technical Services Tutorials and Custom Solutions http://PeltierTech.com/ _______ "Tushar" <Tushar@discussions.microsoft.com> wrote in message news:9441A8E6-7307-4105-B5F9-CBCFC11E93DF@microsoft.com... > For example: > x y > 1 5.5 > 2 8.5 > 3 10.5 > 4 11.5 > For x=1.56, wh...

How to Get Your Lover Back and Bring Back Lost Love !!!
t's great to see a group of people that is so passionate about How to get your ex back, or get your lover back and bring back lost love.People don't realize just how important it is to start to get informations and learn how to get your ex-back so that you will be free from that emotional trauma or torture that we face everyday due to relationships that has broken apart. This is why we need to make sure that the proper information is readily available for everyone. as this will make us happier and healthier . I've got a blog about my experiences with informations and learning h...

Conv Access 97->2000-Gets a method or data member not found error
For the following code which compiles and runs successfully in MS Access 97, when converting to MS Access 2000 the following compile error occurs "Method or data member not found." for the line below. tempID = rs.[UserID] UserID is a field in the tblSecurity table. It seems that the tblSecurity table is not opening in MS Access 2000 since this error will occur using any field, not just UserID. This error does not occur in MS Access 97. PLEASE HELP. The routine is displayed below. Sincerely thanks, Phil ------------------ CODE - Shown Below ------------------ Private Sub...

An Enterprise Project Template
Using Project Server 2007, in MS Project Pro, I create a project schedule and save it as a template to the project server. However, when I click File -> New and then under Templates click on My Computer, there is no tab for Enterprise Templates. How can I get that tab to show? Thx On Dec 15, 8:22=A0am, Shane <shane.garl...@serco-na.com> wrote: > Using Project Server 2007, in MS Project Pro, I create a project > schedule and save it as a template to the project server. However, > when I click File -> New and then under Templates click on My > Computer, there i...

Payables Checks Getting Generated With 0 Value
Hello: When we go to build a batch in the "Select Payables Checks" screen (GP8.00g73), the checks get created, but there are also a number of checks getting created with a value of $0. We do not have any invoices in the system for $0, so we are just wondering what we can do to stop this from happening. Every time we have to go through and manually delete 20-30 $0 value checks in order for the batch to post. Is there any way to find out why these checks are getting generated? This happens because there were previously invoices that were paid by manual payment, so ...

publisher calendar template
I need a template that will allow me to put a yearly calendar (2007 currently) on the back of a business card template (i.e. two sided or even as one part of a folded card template. I'm currently using Pub 2003 but am thinking of the 07 upgrade. Any help would be greatly appreciated Mike One here, scroll down http://msauer.mvps.org/publisher_projects2.htm -- Mary Sauer MSFT MVP http://office.microsoft.com/ http://msauer.mvps.org/ news://msnews.microsoft.com "Added not to request" <Addednottorequest@discussions.microsoft.com> wrote in message news:85E708E3-E90F-48...

templates available for Compaq PDA?
Can any of these templates be dowloaded to a Compaq with a 2000 operating system ...

Excel Template #6
I would like to design an Excel Template where I can input data into a cell and from that input search another spreadsheet which contains numerous cells with information and retrieve the correct set of data from that second spreadsheet into a range of cells on the first spreadsheet. Has anyone ever run across this type of usage? Thanks for any help. The search engine in The Excel Auditor does this. -- Regards Andy Wiggins www.BygSoftware.com Home of "Save and BackUp", "The Excel Auditor" and "Byg Tools for VBA" "RGordon" <rgordon@callone...

Trying to get sumif to work with dates
Hi I am using trying to use the formula shown below, but not getting a result when I should. =SUMIF('MERSEY RAIL'!A6:'MERSEY RAIL'!A100,">=M2",'MERSEY RAIL'! C6:'MERSEY RAIL'!C100) If I put <>, I get a figure, but it is wrong because some of the dates do match. However, ideally I want it to do ">=M2 AND <=M3". Is this possible with SUMIF? Stapes Try it in this form =SUMIF('Another sheet'!A6:A100,"<>"&M2,'Another sheet'!C1:C5) Note: (A) the way the criteria is set up and (B) the range...

Get free e-books!
check this out! http://freebooks2007.blogspot.com If the book you want isn't on the list, just send message to : akira_toya2006@yahoo.com thank you all. ^^ have a good lesson today! How many are legal? It looks a lot like many other blogs hosting ebooks collections referring to illegal downloads. I look at them from time to time as they host also illegal copies of my books. - -- Marco Cantu' (author, Mastering Delphi 2005) http://blog.marcocantu.com - http://www.marcocantu.com --- posted by geoForum on http://www.newswhat.com ...

Hiding columns and getting them back
I hide columns in a spreadsheet, updated it and then I could not get my columns back I did not save it while I was making the changes. Hi select the columns left and right to the hidden ones and goto 'Format - columns - unhide) -- Regards Frank Kabel Frankfurt, Germany "Linda" <Linda@discussions.microsoft.com> schrieb im Newsbeitrag news:68456BE3-8367-443C-8108-C75BE92F4D68@microsoft.com... > I hide columns in a spreadsheet, updated it and then I could not get my > columns back I did not save it while I was making the changes. Linda Hit CRTL + A(twice in XL...

getting msg: cannot sort merged cells not same size
Hi. someone sent me what looks like a run of the mill excel file . When I try to sort it I get a message saying the "operation requires merged cells to be identically sized". All the cells look the same size to me and as far as I know no merging was done to create the file.... I am attempting to contact the creator of the file but so far no luck. any ideas? Thank you. press Ctrl-A to select the entire sheet, then Format>Cells>Alignment and make sure the Merge Cells option is unchecked. "help with mas data" wrote: > Hi. someone sent me what looks like a ru...

Not getting all emails
I just started my account and have been having a lot of problems. I have forwarded my pop email account to windows mail. I have my emails coming to both the Windows mail and my outlook. I'm not getting all emails on Windows mail that I am on my Outlook and so far can not tell why some make it and some don't... can anyone help? This group is for Windows *Live* Mail, not Windows Mail. -- Bruce Hagen MS-MVP [Mail] Imperial Beach, CA "Mic" <Mic@discussions.microsoft.com> wrote in message news:5BE0212C-98A9-40AA-8AE0-8B1CFA1A...

How do I get multilevel category labels to appear horizontal?
I am creating a large 100% stacked bar chart but my 2nd and third categories on my axis appear vertical instead of horizontal is there anyway to change this? I am running Excel 2007 Hi, You can not change the orientation of the outer level category labels as you require, only the inner most level of labels is affected by the Alignment options. If you want full control you will have to fake the axis labels with additional series and data labels or textboxes. Cheers Andy -- Andy Pope, Microsoft MVP - Excel http://www.andypope.info "Chart help needed" <Chart help needed@...

Get the number of records which have each value of an FK
I have an lnkItemState table and want to get the number of records in in that have each value of stateId. if lnkItemState, and lkupState contained the following: lnkItemState itemID StateID ... 1 1 2 1 3 1 4 2 5 2 lkupState StateID ... 1 2 3 I'd like my query to return: StateID ItemCount 1 3 2 2 3 0 How would I write this? Using a Group By query, something like Select StateID , Count(itemID ) As CountOfItems From TableName Group By StateID -- Good Luck BS"D "Dan Neely" wrote: > I ha...