![]() |
![]() | ![]() | ![]() | Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - Param scope error [Thread Next] Re: Param scope errorTo: 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() <= $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() <=
$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/
| ![]() | ![]() | ![]() |
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | |||||
|
