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
594 Views

Similar Articles

[PageSpeed] 51


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 (1778)
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:

Can I Apply Two Filters to Task View?
It seems to me that when I add a filter to a task view for something like category "does not contain" xyz, and then add right below that, category "does not contain" abc, it should show all of my tasks, but just not anyone that has xyz OR abc in the category. But, if I add the first filter, it seems to work ok, but when I add the second, it just makes all of the filtering not work. Am I missing something? when you use two of the same criteria they are OR'd together. Try using abc AND xyz as the condition (it works with some fields but may not work with all) or use ...

Still Getting Junk at "Safe List Only"
After setting the Junk List options to only receive email from my "Safe List Only" I still get one or two junk emails. I have checked the safe list and these addresses are not on the list. Thanks for the help. Vista Home Premium Windows Mail 6 "ADKR" <ADKR@discussions.microsoft.com> wrote in message news:379F2506-5A59-4249-BCE2-E6C9C39A207A@microsoft.com... > After setting the Junk List options to only receive email from my "Safe > List > Only" I still get one or two junk emails. I have checked the safe list > and > the...

Global template or something alike
Hi, Is there something in Visio (2003) like Words Normal.dot or like Excels Personal.xls? I'm looking for some place to store global settings and ever usefull macros. -- Mvg, Frans No, there is no equivalent in Visio. If you have global macros, then it is usual to store them in a stencil for everyone to use. You could include a macro that changes the settings too. "F.H. van Zelm" <fhvzelm@hotmail.com> wrote in message news:eGzYrGjTHHA.4276@TK2MSFTNGP02.phx.gbl... > Hi, > > Is there something in Visio (2003) like Words Normal.dot or like > Excels Pers...

XSL feed-- Metadata -Deployement Mgr
hi when we publish from deployement manager the xsl files are getting changed!!! my question is from which table(or tables) of the MSCRM, the metadata for the XSL is feeded??? Thanks in advance OrganizationUIBase Mike greaterthantwo media Printable Quotes, Orders and Invoices, with line-item details, now available for MSCRM. http://www.greaterthantwo.com "Apple" <none@nospam.com> wrote in message news:ueXyX%233%23DHA.3536@TK2MSFTNGP10.phx.gbl... > hi > when we publish from deployement manager the xsl files are getting > changed!!! > > my question is fro...

Apply Sales Documents store procedures error
Our client is on v 8.0 and gets the following error randomly in Apply Sales Documents window: "The stored procedure PopulateRMOpenTempTable. Pass Through SQL returned the following results: DBMS: 11, Great Plains. -- cal 11 is a network error, usually coming from the OLEDB client. Try checking your ODBC connection and make certain that all the ANSI settings "Create temporary stored procedeures", etc are turned off. Dwight "cal" <cal@discussions.microsoft.com> wrote in message news:7AF9E389-03BA-4BD2-A529-9CD4CF260B1C@microsoft.com... > Our client is...

How to get the 'modified' time of a file?
I need a way to get the modified time of a file (the same data you can get by right clicking the file on the file explorer) So I have writen: CTime GetTime(LPCTSTR name) { if (f.Open(name,CFile::modeRead)) { CFileStatus fileStat; if (f.GetStatus(fileStat)) return fileStat.m_mtime; } return 0; } In most cases this works just fine. The problem is that CFile::Open sometimes fails. Usually because the file is being read elsewhere. So this solution is not good enough for me. Is there a better (safer) way to receive this data? Maybe ...

xsl:with-param fails in XSL that accepts arguments from XML control
Hi, why does with-param fail to send parameters to any templates in a stylesheet that also accepts arguments from the ASP.NET XML control? The argument from the XML control seems to be available to any template in the stylesheet, even if a parameter for the argument is NOT coded for a template call. On the other hand, any parameters coded for a template call don't seem to pass their values (the stylesheet doesn't crash - everything is still rendered). ASP.NET C# code that loads the xml control xmlCtrl.TransformSource="template.xsl"; XsltArgumentList args1 = new XsltArgum...

Templates #2
I am trying to create a template for a newsletter on P2000. Is it true that Microsoft forces you to use their template folder? Can't seem to save it elsewhere. A small child turns to Ed, and exclaims: "Look! Look! A post from Builder <dovbaer353@yahoo.com>!"... > I am trying to create a template for a newsletter on P2000. Is it > true that Microsoft forces you to use their template folder? Can't > seem to save it elsewhere. If you want to save the file as a template that can be used to create future publications from by using New > From Template, the te...

url in email template
hi all, i have a url filed (new_urlofdepartment) in my case form and that field is sent to some users via worklfow and workflow uses an email template. Everythin is fine but the url is seen as text not hyperlink when the users receive emails. Any suggestion about how to make this filed a hyperlink? You could write a custom workflow activity that sends back the html hyperlink. When you do that, the link is integrated and you see only the hyperlink text, not the link itself -- Tanguy T My blog : http://mscrmtools.blogspot.com "crmguy" <crmguy@discussions.microsoft.com> ...

How can I get Excel to show this?????
In cell A1, I have a drop down menu with 3 names in it, (Davis, Jones Smith) When I select on of their names I want cell A2 to show the cod name that I have given for that person. For example, in cell A1 select Jones, I want A2 to automatically show Broom, the code name have given Mr. Jones. Mile -- mcr ----------------------------------------------------------------------- mcr1's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=1549 View this thread: http://www.excelforum.com/showthread.php?threadid=27759 You mean for it to disappear when it is no longer sel...

Problem when Loading XSL file using XslCompiledTransform
Hi, I am testing the scenario to migrate from MSMXL4 to .NET2.0 system.xml. I experienced xsl file loading problem whenever the xsl file have a user defined script in it. The error message is as follow: "Objects of type 'Script2' do not have such a member" The above error only happens when I set the XsltSettings.TrustedXslt ans use the following statement to load xsl file: objxslcompiledtransform.Load(input, XsltSettings.TrustedXslt , new XmlUrlResolver()); Can anyone tell me what is happening here? Sample Xsl script: <msxsl:script language="javascript" ...

Get Rich
Take advantage of a great deal ...

Case owners email in a template
Trying to create an email template to use for a New Case Acknowledgment. I would like to include the email address of the case owner in the template. In the template editor, I can only pull the owner's name from the Case entity. The User entity is available but this is the user executing the template, not the case's owning user. In looking at the xml generated for the template, I see it using "slugs" formatted like: xsl:choose><xsl:when test="incident/ownerid/@name"><xsl:value-of select="incident/ownerid/@name" /></xsl:when><...

How can I get Dictionaries for Office XP?
I find vague references online to to an "Office XP Proofing tools" but the online stores seem to have no references to it - only Office 2003 Proofing tools. Is that compatible with Office XP? If not, where can I find proofing tools for XP. Or alternatively, where can I get dictionaries and grammar checkers for individual languages for Office XP. No, they are not compatible. If you can still find Office 2003 Proofing Tools online, then I would advise upgrading to Office 2003 so you could use Office 2003 Proofing Tools. You have very little chance of finding Office XP...

xsl:if and string function
I'm at my wit's end with this one. Within an xsl:if test, I'm not able to get 2 variables to properly evaluate if one of them is wrapped within a string function. <!-- This works --> <xsl:if test="$var:v141=&quot;true&quot;"> <!-- This doesn't work --> <xsl:if test="string($var:v141)=&quot;true&quot;"> I can't figure out why. The transformation is taking place within dotnet and the var:v141 is assigned through a function call and it doesn't matter if I return a boolean value or a string value ("true&quo...

How to get the default browser
Is the any way to get the default browser in a system? Is there any registry value to know that? I want to check that through program.... Thanks, Deep On 17 May 2007 06:12:22 -0700, deep <joydeep.ball@gmail.com> wrote: >Is the any way to get the default browser in a system? Is there any >registry value to know that? I want to check that through program.... Maybe it is: HKEY_CLASSES_ROOT HTTP shell open ddeexec Application HKEY_CLASSES_ROOT\HTTP\shell\open\ddeexec\Application MrAsm I think what Paul writes here still works... I am runni...

Applying Patches To W2K3 \ E2K3 Cluster
I am trying to find information on how to apply the recent hotfixes released by MS to a W2K3 \ E2K3 SPK1 Cluster I have the procedures for applying a service pack but i have no idea if i do the same procedures when applying a HotFix. Does anybody know how to do this or has already done this and can help me out? On Mon, 25 Oct 2004 12:55:33 -0400, "Chris Miller" <cmiller@everestre.com> wrote: >I am trying to find information on how to apply the recent hotfixes released >by MS to a W2K3 \ E2K3 SPK1 Cluster >I have the procedures for applying a service pack but i have...

Get the Microsoft Dynamics CRM 3.0 Data Migration Pack
Today we released our Data Migration Pack for Microsoft Dynamics CRM 3.0. It includes: o Data Migration Framework 3.0 An updated version of the tool we provided for 1.2, now enhanced with a explanatory interface that guides users through the data migration process. This is the main tool used when migrating data into CRM from different systems. o Data Migration Wizard for Microsoft Office Outlook with Business Contact Manager An end-to-end wizard targeted at the Small Business Edition users. An easy-to-use migration option is provided for users coming from Business Contact Manager...

is it possible to execute write to the fields in another .xsl form a macro in another .xsl? e.g. some way to load another .xsl into an .xsl macro and write to its data?
is it possible to execute write to the fields in another .xsl form a macro in another .xsl? e.g. some way to load another .xsl into an .xsl macro and write to its data? i mean xls not xsl "Daniel" <softwareengineer98037@yahoo.com> wrote in message news:eDjijGEeFHA.2584@tk2msftngp13.phx.gbl... > is it possible to execute write to the fields in another .xsl form a macro > in another .xsl? e.g. some way to load another .xsl into an .xsl macro and > write to its data? > > Both workbooks are open? workbooks("book1.xls").worksheets("sheet1")...

Create Excel through XSL including image
Hi I need to create an Excel file from XML through XSL using MS-Office 2003 XML schema. However, I'm able to create the Excel file, but unable to display/create images in the Excel sheet. Can anyone help me out on how to do this ? Thanks Snig. ...

I cannot send e-mails. I get this
The host 'SMTP' could not be found. Please verify that you have entered the server name correctly. Subject '', Account: 'POP3 (3)', Server: 'SMTP', Protocol: SMTP, Port: 25, Secure(SSL): No, Socket Error: 11001, Error Number: 0x800CCC0D Windows Mail: Setting up an account from start to finish http://windows.microsoft.com/en-US/windows-vista/Windows-Mail-setting-up-an-account-from-start-to-finish You need to get the correct settings from your mail server. Yours aren't correct. -- Bruce Hagen MS-MVP [Mail] Imperial...

getting data from another cell
Hi I'm having a column A2 of full name eg (HOWES,CARRIE,L) I want to copy the first name, last name and the inital to three another cells like A3 LAST NAME = HOWES, A4 FIRST NAME = CARRIE, A5 MI = L Please help me to do it . Thanks jack Go to Data > Text to columns and use comma as your delimiter. HTH Jason Atlanta, GA >-----Original Message----- >Hi > I'm having a column A2 of full name eg (HOWES,CARRIE,L) I want to copy >the first name, last name and the inital to three another cells like A3 LAST >NAME = HOWES, A4 FIRST NAME = CARRIE, A5 MI = ...

in C# how do i transform an xml document with an xsl document when my xml document is a string and my xsl document is a string? the msdn examples only show how to do it with steams and files. in my ca
in C# how do i transform an xml document with an xsl document when my xml document is a string and my xsl document is a string? the msdn examples only show how to do it with steams and files. in my case i have everything in string Daniel wrote: > in C# how do i transform an xml document with an xsl document when my xml > document is a string and my xsl document is a string? the msdn examples only > show how to do it with steams and files. in my case i have everything in > string Use a StringReader - if you want to output it to a string, use StringWriter. ...

Newbie here
Hi, this is one great ng! I've been reading for hours and find it enormously informative. Thanks. I'm a newbie to the ng but not entirely to Excel. I'm still on '97 (not 2000) I know how to format the workbook template (book1.xlt) to open with the settings (margins, custom header etc) that I prefer, but every time that I open a new worksheet within the same workbook, it gives me the original Excel settings that it has always given me - unless, of course, I *copy* the worksheet already formatted by me - but it is inconvenient to do that every time. I've tried to loca...

GET.CHART.ITEM returning strange results
I have some functionality written in VB that I am re-writing in C#, but I am getting a different result from the GET.CHART.ITEM macro for the exact same chart series point. This is running in Excel 2003. An example: VB CODE: --> result is 337.5 Dim returnValue as variant Series.points(1).select returnValue = Application. ExecuteExcel4Macro("GET.CHART.ITEM(1,1)") C# CODE: --> result is 309.25 Series.points(1).select object returnValue = _application.ExecuteExcel4Macro(("GET.CHART.ITEM(1,1)"); Another interesting note is that I run the same C# code on the sa...