Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Question on flow

From: "tshad" <tshad@----------.--->
To: NULL
Date: 4/1/2008 12:59:00 PM

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.  Based on how mine works 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.  If I don't call any 
other function, from a startup function then only the startup function gets 
executed even if there there are other functions in my program (discounting 
events, of course).

In XSLT, it seems that the 1st template is like your startup routine.  If 
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.  If 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.  As it works exactly the same 
if I change it to <REPORTING>.  In the copy case, it will put whatever my 
root element is as my new root element and the other case will put 
<REPORTING> as my root element.  Other 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.  But if I have "/" and 
<xsl:copy>, I don't get a root tag.  If I do "/" and "<REPORTING> (in place 
of the <xsl:copy>), it works fine with <REPORTING> as my root tag.

************************************************
<xsl:stylesheet
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">

 <xsl:output method="xml" indent="yes"/>

 <xsl:template match="REPORT">
  <xsl:copy>
   <xsl:apply-templates
  select="FORMS/FORM/FIELDS/*[not(starts-with(name(), 'SCMCOMMENTS')) and
not(starts-with(name(), 'GEN_COMMENTS')) and not(starts-with(name(),
'CMPHIST_TXT'))]"/>
   <form>
    <sectionNumber>0</sectionNumber>
    <primary>True</primary>
    <formName>
     <xsl:value-of select="FORMS/FORM/@FORMCODE"/>
    </formName>
    <tagName>SCMCOMMENTS_1</tagName>
    <flags>0</flags>
    <format>0</format>
    <value>
     <xsl:apply-templates select="FORMS/FORM/FIELDS/*[starts-with(name(),
'SCMCOMMENTS')]"/>
    </value>
   </form>
   <form>
    <sectionNumber>0</sectionNumber>
    <primary>True</primary>
    <formName>
     <xsl:value-of select="FORMS/FORM/@FORMCODE"/>
    </formName>
    <tagName>GEN_COMMENTS_1</tagName>
    <flags>0</flags>
    <format>0</format>
    <value>
     <xsl:apply-templates select="FORMS/FORM/FIELDS/*[starts-with(name(),
'GEN_COMMENTS')]"/>
    </value>
   </form>
   <form>
    <sectionNumber>0</sectionNumber>
    <primary>True</primary>
    <formName>
     <xsl:value-of select="FORMS/FORM/@FORMCODE"/>
    </formName>
    <tagName>CMPHIST_TXT</tagName>
    <flags>0</flags>
    <format>0</format>
    <value>
     <xsl:apply-templates select="FORMS/FORM/FIELDS/*[starts-with(name(),
'CMPHIST_TXT')]"/>
    </value>
   </form>
   <form>
    <sectionNumber>
     <xsl:value-of select="FORMS/FORM/@SECCODE"/>
    </sectionNumber>
    <primary>True</primary>
    <formName>
     <xsl:value-of select="FORMS/FORM/@FORMCODE"/>
    </formName>
    <tagName>FormFormats</tagName>
    <flags>0</flags>
    <format>0</format>
    <value>
     <xsl:apply-templates select="FORMS/FORM/@*"/>
    </value>
   </form>
   <xsl:apply-templates select="FORMS/FORM/attachments/attachment"/>
  </xsl:copy>
 </xsl:template>

 <xsl:template match="FIELDS/*[not(starts-with(name(), 'SCMCOMMENTS')) and
not(starts-with(name(), 'GEN_COMMENTS')) and not(starts-with(name(),
'CMPHIST_TXT'))]">
  <form>
   <sectionNumber>
    <xsl:text>0</xsl:text>
   </sectionNumber>
   <primary>True</primary>
   <formName>
    <xsl:value-of select="../../@FORMCODE"/>
   </formName>
   <tagName>
    <xsl:value-of select="name()"/>
   </tagName>
   <flags>0</flags>
   <format>0</format>
   <value>
    <xsl:value-of select="."/>
   </value>
  </form>
 </xsl:template>

 <xsl:template match="FIELDS/*[starts-with(name(), 'SCMCOMMENTS')]">
  <xsl:value-of select="."/>
  <xsl:if test="position() != last()">
   <xsl:text> </xsl:text>
  </xsl:if>
 </xsl:template>
 <xsl:template match="FIELDS/*[starts-with(name(), 'GEN_COMMENTS')]">
  <xsl:value-of select="."/>
  <xsl:if test="position() != last()">
   <xsl:text> </xsl:text>
  </xsl:if>
 </xsl:template>
 <xsl:template match="FIELDS/*[starts-with(name(), 'CMPHIST_TXT')]">
  <xsl:value-of select="."/>
  <xsl:if test="position() != last()">
   <xsl:text> </xsl:text>
  </xsl:if>
 </xsl:template>

 <xsl:template match="FORM/@*">
  <xsl:value-of select="concat(name(), '=', .)"/>
  <xsl:if test="position() != last()">
   <xsl:text> </xsl:text>
  </xsl:if>
 </xsl:template>

</xsl:stylesheet>
************************************************

Am I close?

Thanks,

Tom 




transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent