Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Param scope error

From: Martin Honnen <mahotrash@-----.-->
To: NULL
Date: 5/7/2004 1:29:00 PM

~J~ wrote:


> Could someone please explain what I'm doing wrong with me XSL.
> 
> <?xml version='1.0' encoding="UTF-8" ?><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"><xsl:template match="DistributionLists"><xsl:param name='currentRecord' select="'1'" /><xsl:param name='pageSize' select="'10'"/><xsl:param name='distList' select="'List1'" /><xsl:param name='sort' select="'N'" /><xsl:variable name="maxRecords" select="count(/DistributionLists/List2)" /><HTML><BODY><TABLE id="tblResults" cellSpacing="0" cellPadding="5" width="100%" align="center" border="0"><tr class="distListHeader"><td>Mailbox #</td><td>Distributor name</td><td>Level</td></tr><xsl:apply-templates select="*[local-name()=$distList]/member"><xsl:sort select='*[local-name()=$sort]' order="ascending" /></xsl:apply-templates></TABLE></BODY></HTML></xsl:template><xsl:template match="member"><xsl:if test="position() >= $currentRecord and position() &lt;= $currentRecord + $pageSize"><xsl:for-each select="."><tr class="distListItem"><td><xsl:value-of select="ID" />
</td><td><xsl:value-of select="N" /></td><td><xsl:if test="L=8"><img src="../../images/common/distributorLevels/level7.gif"></img></xsl:if><xsl:if test="L=7"><img src="../../images/common/distributorLevels/level6.gif"></img></xsl:if><xsl:if test="L=6"><img src="../../images/common/distributorLevels/level5.gif"></img></xsl:if><xsl:if test="L=5"><img src="../../images/common/distributorLevels/level4.gif"></img></xsl:if><xsl:if test="L=4"><img src="../../images/common/distributorLevels/level3.gif"></img></xsl:if><xsl:if test="L=3"><img src="../../images/common/distributorLevels/level2.gif"></img></xsl:if><xsl:if test="L=2"><img src="../../images/common/distributorLevels/level1.gif"></img></xsl:if></td></tr></xsl:for-each></xsl:if></xsl:template></xsl:stylesheet>

Posting a stylesheet as one long line doesn't improve your chances that 
anyone finds errors in it. I guess that line worm is the result of using 
the web interface to the MS newsgroups therefore consider to access 
these groups via the news server news.microsoft.com to hopefully then be 
able to post well formatted source code.

Lets try to reformat your stylesheet

<?xml version='1.0' encoding="UTF-8" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
version="1.0">
   <xsl:template match="DistributionLists">
     <xsl:param name="currentRecord" select="'1'"/>
     <xsl:param name="pageSize" select="'10'"/>
     <xsl:param name="distList" select="'List1'"/>
     <xsl:param name="sort" select="'N'"/>
     <xsl:variable name="maxRecords" 
select="count(/DistributionLists/List2)"/>
     <HTML>
       <BODY>
         <TABLE id="tblResults" cellSpacing="0" cellPadding="5" 
width="100%" align="center" border="0">
           <tr class="distListHeader">
             <td>Mailbox #</td>
             <td>Distributor name</td>
             <td>Level</td>
           </tr>
           <xsl:apply-templates select="*[local-name()=$distList]/member">
             <xsl:sort select="*[local-name()=$sort]" order="ascending"/>
           </xsl:apply-templates>
         </TABLE>
       </BODY>
     </HTML>
   </xsl:template>
   <xsl:template match="member">
     <xsl:if test="position() >= $currentRecord and position() &lt;= 
$currentRecord + $pageSize">
       <xsl:for-each select=".">
         <tr class="distListItem">
           <td>
             <xsl:value-of select="ID"/>
           </td>
           <td>
             <xsl:value-of select="N"/>
           </td>
           <td>
             <xsl:if test="L=8">
               <img 
src="../../images/common/distributorLevels/level7.gif"></img>
             </xsl:if>
             <xsl:if test="L=7">
               <img 
src="../../images/common/distributorLevels/level6.gif"></img>
             </xsl:if>
             <xsl:if test="L=6">
               <img 
src="../../images/common/distributorLevels/level5.gif"></img>
             </xsl:if>
             <xsl:if test="L=5">
               <img 
src="../../images/common/distributorLevels/level4.gif"></img>
             </xsl:if>
             <xsl:if test="L=4">
               <img 
src="../../images/common/distributorLevels/level3.gif"></img>
             </xsl:if>
             <xsl:if test="L=3">
               <img 
src="../../images/common/distributorLevels/level2.gif"></img>
             </xsl:if>
             <xsl:if test="L=2">
               <img 
src="../../images/common/distributorLevels/level1.gif"></img>
             </xsl:if>
           </td>
         </tr>
       </xsl:for-each>
     </xsl:if>
   </xsl:template>
</xsl:stylesheet>

> If I run the above, I get an error regarding the scope of the variable or param called "currentRecord".  If I replace my $currentRecord text with a number, I then get an error regarding the $pageSize param...!

You have declared your variables and parameters inside of one template 
but try to use them in another template while in XSLT a param or 
variable is in scope only in the template it is defined in. You 
therefore need to pass params from one template to the other if you need 
a value in several templates

-- 

	Martin Honnen
	http://JavaScript.FAQTs.com/



transparent
Print
Mail
Digg
delicious
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