RE: [xsl] Problems passing parameters

Subject: RE: [xsl] Problems passing parameters
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Sat, 26 Feb 2005 10:20:57 -0000
<xsl:template> can't have xsl:with-param as a child. It should be xsl:param.
I'm surprised you don't get a simple syntax error for this. Also, in
contains(@href, 'http://www.hostname)'">, the closing single quote should be
before the closing ")". 

Perhaps this isn't an accurate transcript of the code that failed?

xsl:document was introduced in the draft XSLT 1.1 specification which never
came to anything, though it was implemented in one or two products including
Saxon 6.x. It's superseded in XSLT 2.0 by xsl:result-document. It would be
useful to know what XSLT processor/version you are using.

Nesting 8 levels of xsl:choose to pick up the first 8 steps in a URI is not
very elegant coding. You need to use recursion here.

Michael Kay

> -----Original Message-----
> From: Tibbetts, Jeffery A. NGIC [mailto:frtibja@xxxxxxxxxxxxx] 
> Sent: 25 February 2005 17:59
> To: 'xsl-list@xxxxxxxxxxxxxxxxxxxxxx'
> Subject: [xsl] Problems passing parameters
> I am unsuccessfully trying to access the value of a passed 
> parameter.  The
> overall effort here is to open a linked document and provide 
> the requisite
> path to the linked file to replace links to a generic http://hostname
> address with a local path (think of making a cd layout from a 
> set of web
> documents based on an RSS feed).
> This is the relevant part of the stylesheet code.  I seem to 
> be able to
> access the value of the passed parameter with a value-of 
> select statement,
> but as soon as I nest the call to the parameter inside a choose/when
> statement I get an empty string.  It seems to me the passed 
> parameter is
> supposed to be in context throughout the template, so I am 
> unsure of why I
> can access it in one manner but not another.
> If there is another manner of accessing this information from the file
> itself without passing it as a parameter I am open to 
> suggestions.  Thus far
> I have not been able to find another way.  Please help.
> <xsl:template match="item/link">
> <xsl:variable name="test" select="../link/text()"/>
> <xsl:variable name=initial select="concat('/home_directory',
> (substring-after($test, 'http://www.hostname')))"
> <xsl:for-each select="document($initial)/>
> <xsl:document href="{concat($inital,'l')}" method="html"
> encoding="ISO-8859-1" omit-xml-declaration="no">
> <xsl:apply-templates mode="internal_url">
> <xsl:with-param name="initial" select=$initial/>
> </xsl:apply-templates>
> </xsl:document>
> <xsl:template match="@*|node()" mode="internal_url">
> <xsl:with-param name="initial">
> <xsl:choose>
> <xsl:when test="string-length(@href)='19' and contains(@href,
> 'http://www.hostname)'">
> 	<xsl:choose>
> 		<xsl:when test=contains($initial, '/')>
> 			<!--nested choose statements until I 
> get to 8 levels
> of depth -not repeated here - -->
> 		</xsl:when>
> 		<xsl:otherwise>
> 		<xsl:variable name="level" select=concat('./', 
> 'index.htm')
> 		<a href={concat('./','index.htm')><xsl:apply-templates
> mode="internal_url"/></a>
> 		</xsl:otherwise>
> </xsl:when>
> <xsl:otherwise>
> <xsl:copy>
> <xsl:apply-templates select="@*|node() mode="internal_url"/>
> </xsl:copy>
> </xsl:otherwise>
> </xsl:choose>
> </xsl:template>
> Jeffrey A. Tibbetts
> Markup Language Specialist
> National Ground Intelligence Center
> 980-7782
> frtibja@xxxxxxxxxxxxx

Current Thread