Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - Question on flow [Thread Next] Re: Question on flowTo: NULL Date: 4/2/2008 4:03:00 AM On Apr 2, 12:59=A0am, "tshad" <ts...@dslextreme.com> wrote: > I have been working on my XSLT page and have a couple questions on flow. > > In my example XSLT file, I have have 4 Templates. =A0Based on how mine wor= ks I > think I understand how the flow works but am not sure. > > It seems that only the 1st template is the driving template, similar to > Main() in C or the startup function in any program. =A0If I don't call any= > other function, from a startup function then only the startup function get= s > executed even if there there are other functions in my program (discountin= g > events, of course). > > In XSLT, it seems that the 1st template is like your startup routine. =A0I= f > you don't do an <xsl:apply-templates> or <xsl:call-template> only this 1st= > template will get run and it will execute all the commands in it until it > hits the </xsl:template> tag. > > All the other templates get executed only if they are applied or called. > > This seems to be what happens. =A0If I take all the apply-templates out of= my > 1st template, none of the other templates get executed and all the 1st > template does. > > I am a little confused on the necessity of using the <xsl:copy> (except to= > soft code the root element), as in my example. =A0As it works exactly the = same > if I change it to <REPORTING>. =A0In the copy case, it will put whatever m= y > root element is as my new root element and the other case will put > <REPORTING> as my root element. =A0Other than that, there doesn't seem to = be > any difference. > > I also am a little confused as to the use of "/*" vs "/" vs "REPORT" in my= > first template line. > > Both "/*" and "REPORT" give me the same results. =A0But if I have "/" and > <xsl:copy>, I don't get a root tag. =A0If I do "/" and "<REPORTING> (in pl= ace > of the <xsl:copy>), it works fine with <REPORTING> as my root tag. > > ************************************************ > <xsl:stylesheet > =A0 =A0 xmlns:xsl=3D"http://www.w3.org/1999/XSL/Transform" > =A0 =A0 version=3D"1.0"> > > =A0<xsl:output method=3D"xml" indent=3D"yes"/> > > =A0<xsl:template match=3D"REPORT"> > =A0 <xsl:copy> > =A0 =A0<xsl:apply-templates > =A0 select=3D"FORMS/FORM/FIELDS/*[not(starts-with(name(), 'SCMCOMMENTS')) = and > not(starts-with(name(), 'GEN_COMMENTS')) and not(starts-with(name(), > 'CMPHIST_TXT'))]"/> > =A0 =A0<form> > =A0 =A0 <sectionNumber>0</sectionNumber> > =A0 =A0 <primary>True</primary> > =A0 =A0 <formName> > =A0 =A0 =A0<xsl:value-of select=3D"FORMS/FORM/@FORMCODE"/> > =A0 =A0 </formName> > =A0 =A0 <tagName>SCMCOMMENTS_1</tagName> > =A0 =A0 <flags>0</flags> > =A0 =A0 <format>0</format> > =A0 =A0 <value> > =A0 =A0 =A0<xsl:apply-templates select=3D"FORMS/FORM/FIELDS/*[starts-with(= name(), > 'SCMCOMMENTS')]"/> > =A0 =A0 </value> > =A0 =A0</form> > =A0 =A0<form> > =A0 =A0 <sectionNumber>0</sectionNumber> > =A0 =A0 <primary>True</primary> > =A0 =A0 <formName> > =A0 =A0 =A0<xsl:value-of select=3D"FORMS/FORM/@FORMCODE"/> > =A0 =A0 </formName> > =A0 =A0 <tagName>GEN_COMMENTS_1</tagName> > =A0 =A0 <flags>0</flags> > =A0 =A0 <format>0</format> > =A0 =A0 <value> > =A0 =A0 =A0<xsl:apply-templates select=3D"FORMS/FORM/FIELDS/*[starts-with(= name(), > 'GEN_COMMENTS')]"/> > =A0 =A0 </value> > =A0 =A0</form> > =A0 =A0<form> > =A0 =A0 <sectionNumber>0</sectionNumber> > =A0 =A0 <primary>True</primary> > =A0 =A0 <formName> > =A0 =A0 =A0<xsl:value-of select=3D"FORMS/FORM/@FORMCODE"/> > =A0 =A0 </formName> > =A0 =A0 <tagName>CMPHIST_TXT</tagName> > =A0 =A0 <flags>0</flags> > =A0 =A0 <format>0</format> > =A0 =A0 <value> > =A0 =A0 =A0<xsl:apply-templates select=3D"FORMS/FORM/FIELDS/*[starts-with(= name(), > 'CMPHIST_TXT')]"/> > =A0 =A0 </value> > =A0 =A0</form> > =A0 =A0<form> > =A0 =A0 <sectionNumber> > =A0 =A0 =A0<xsl:value-of select=3D"FORMS/FORM/@SECCODE"/> > =A0 =A0 </sectionNumber> > =A0 =A0 <primary>True</primary> > =A0 =A0 <formName> > =A0 =A0 =A0<xsl:value-of select=3D"FORMS/FORM/@FORMCODE"/> > =A0 =A0 </formName> > =A0 =A0 <tagName>FormFormats</tagName> > =A0 =A0 <flags>0</flags> > =A0 =A0 <format>0</format> > =A0 =A0 <value> > =A0 =A0 =A0<xsl:apply-templates select=3D"FORMS/FORM/@*"/> > =A0 =A0 </value> > =A0 =A0</form> > =A0 =A0<xsl:apply-templates select=3D"FORMS/FORM/attachments/attachment"/>= > =A0 </xsl:copy> > =A0</xsl:template> > > =A0<xsl:template match=3D"FIELDS/*[not(starts-with(name(), 'SCMCOMMENTS'))= and > not(starts-with(name(), 'GEN_COMMENTS')) and not(starts-with(name(), > 'CMPHIST_TXT'))]"> > =A0 <form> > =A0 =A0<sectionNumber> > =A0 =A0 <xsl:text>0</xsl:text> > =A0 =A0</sectionNumber> > =A0 =A0<primary>True</primary> > =A0 =A0<formName> > =A0 =A0 <xsl:value-of select=3D"../../@FORMCODE"/> > =A0 =A0</formName> > =A0 =A0<tagName> > =A0 =A0 <xsl:value-of select=3D"name()"/> > =A0 =A0</tagName> > =A0 =A0<flags>0</flags> > =A0 =A0<format>0</format> > =A0 =A0<value> > =A0 =A0 <xsl:value-of select=3D"."/> > =A0 =A0</value> > =A0 </form> > =A0</xsl:template> > > =A0<xsl:template match=3D"FIELDS/*[starts-with(name(), 'SCMCOMMENTS')]"> > =A0 <xsl:value-of select=3D"."/> > =A0 <xsl:if test=3D"position() !=3D last()"> > =A0 =A0<xsl:text> </xsl:text> > =A0 </xsl:if> > =A0</xsl:template> > =A0<xsl:template match=3D"FIELDS/*[starts-with(name(), 'GEN_COMMENTS')]"> > =A0 <xsl:value-of select=3D"."/> > =A0 <xsl:if test=3D"position() !=3D last()"> > =A0 =A0<xsl:text> </xsl:text> > =A0 </xsl:if> > =A0</xsl:template> > =A0<xsl:template match=3D"FIELDS/*[starts-with(name(), 'CMPHIST_TXT')]"> > =A0 <xsl:value-of select=3D"."/> > =A0 <xsl:if test=3D"position() !=3D last()"> > =A0 =A0<xsl:text> </xsl:text> > =A0 </xsl:if> > =A0</xsl:template> > > =A0<xsl:template match=3D"FORM/@*"> > =A0 <xsl:value-of select=3D"concat(name(), '=3D', .)"/> > =A0 <xsl:if test=3D"position() !=3D last()"> > =A0 =A0<xsl:text> </xsl:text> > =A0 </xsl:if> > =A0</xsl:template> > > </xsl:stylesheet> > ************************************************ > > Am I close? > > Thanks, > > Tom Hi, Lot of peopls they misunderstood here. '/' mention doucment element not root element. your using <xsl:template match=3D"/"> <xsl:apply-templates/> </xsl:template> it shows document element inside content to be pushed to other templates. And put your XML input file. Regards, Balaji. M | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
