ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> xsl-list
xsl-list
RE: [xsl] About and
by other posts by this author
Nov 5 2002 12:45PM messages near this date
Re: [xsl] Word Highlighting | RE: RE: [xsl] JavaScript problem again!
FAQ,

>  In the next xsl I want to make that the param "cod" be 
>  incremented in each time that the <xsl:for-each> cicle 
>  occurs, but it's result is an error:
>  
>  "javax.xml.transform.TransformerException: xsl:with-param is 
>  not allowed in this position in the stylesheet!"
>  
>  Why?!
>  Tks
>  
>  <?xml version="1.0" encoding="ISO-8859-1"?>
>  <xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>      version="1.0"
>      xmlns:xalan="http://xml.apache.org/xslt">
>  	<xsl:param name="cod">0</xsl:param>
>  	<xsl:output method="html"/>
>  	<xsl:template match="/">
>      		<xsl:for-each select=".//Boy">
>      			<xsl:with-param name="cod" 
>  select="number($cod+1)"/>
>  			<!--make other things-->
>  		</xsl:for-each>
>  	</xsl:template>
>  </xsl:transform>

XSLT doesn't allow you to update parameter values after they've been bound. Repeat "recursio
n is my friend" ten times, and you'll get the hang of it.

Anyhow, rewrite your stylesheet to

  <xsl:param name="cod" select="0" /> 
  <xsl:template match="/"> 
    <xsl:for-each select="//Boy"> 
      <xsl:variable name="_cod" select="$cod + position()" /> 
	<!--make other things--> 
    </xsl:for-each> 
  </xsl:template> 

And use $_cod instead of $cod in "make other things". Use select attribute in the xsl:param 
to bind the parameter into a number, instead of a RTF <http://www.w3.org/TR/xslt#section-Res
ult-Tree-Fragments> .

Cheers,

Jarno

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved