xsl-list
[Top] [All Lists]

RE: Node-sets using <xsl:with-param>

2004-01-22 13:23:56
Your recursive call on the template with mode=modify

              <xsl:apply-templates mode="modify">
                 <xsl:with-param name="id1" 
select="$newid"></xsl:with-param>
             </xsl:apply-templates>

does not set the $curnode parameter. This means it will take its default
value, which is a zero-length string. Doing an apply-templates on a
zero-length string will give you a type error.

Michael Kay

-----Original Message-----
From: owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com 
[mailto:owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com] On Behalf Of 
Mir Farooq Ali
Sent: 22 January 2004 17:11
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: Re: [xsl] Node-sets using <xsl:with-param>


G. Ken Holman wrote:

At 2004-01-22 00:26 -0500, Mir Farooq Ali wrote:

I'm getting an error when trying to pass the current node into a
template using <xsl:with-param name="current" 
select="current()"/> or 
<xsl:with-param name="current" select="."/>

The place where I'm trying to access it
<xsl:apply-templates mode="structure1" select="$current"/> 
 is where
I'm getting an error message using Saxon indicating that 
the select 
attribute is expecting node and what it's getting is xs:string.

What am I doing wrong here?


I think we need more code fragments to see ... nothing strikes me as
incorrect in the two snippets you've given.

If you are using <xsl:with-param/> inside of <xsl:apply-templates/> 
(you
don't say if you are using <xsl:call-template or not) make sure you 
don't have any built-in templates being triggered between 
the processing 
of the two templates.  If so, the built-in template will 
not pass the 
node parameter, the template with the parameter declaration 
will get 
called by the built-in template with no parameters, the 
default value 
for an empty parameter declaration is string, and you will 
have an empty 
string passed for the <xsl:apply-templates/>.

But that is just a guess based on your evidence.

I hope this helps.

......................... Ken

This is my stylesheet

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; 
version="1.0">
     <xsl:strip-space elements="*" />
     <xsl:output method="xml" indent="yes" />
     <xsl:variable name="maindoc" select="/" />
     <xsl:template match="TM">
         <UI>
             <STR>
                 <xsl:apply-templates select="T" mode="structure1" />
             </STR>
         </UI>
     </xsl:template>
     <xsl:template match="T" mode="structure1">
         <xsl:variable name="id" select="@Identifier" />
         <xsl:variable name="ttm" select="./Type" />
         <xsl:variable name="tc" select="@Category" />
         <xsl:variable name="uc" select="./Prefs/UC" />
         <xsl:variable name="ups" select="./Prefs/UPS" />
         <xsl:for-each select="document('lookup.xml')">
             <xsl:variable name="current" select="." />
             <xsl:apply-templates mode="modify" select="/TM/
                TC[(_at_)name=$tc]/
                TTM[(_at_)type=$ttm]/
                UCM[(_at_)prefnum=$uc]/
                UPS/part[(_at_)prefnum=$ups]/*">
                 <xsl:with-param name="id1" select="$id"/>
                 <xsl:with-param name="curnode" select="."/>
             </xsl:apply-templates>
         </xsl:for-each>
     </xsl:template>
     <xsl:template mode="modify" match="*">
         <xsl:param name="id1"></xsl:param>
         <xsl:param name="curnode"></xsl:param>
         <xsl:variable name="idd" select="translate($id1,' 
','_')"></xsl:variable>
         <xsl:variable name="newid" select="concat($idd, 
position())"></xsl:variable>
         <part class="{name()}" id="{$newid}">
             <xsl:apply-templates mode="modify">
                 <xsl:with-param name="id1" 
select="$newid"></xsl:with-param>
             </xsl:apply-templates>
             <!--xsl:apply-templates mode="structure1" 
select="$curnode" 
/--> <!-----******* Error on this line here -->
         </part>
     </xsl:template>
     <xsl:template match="Prefs|Type" mode="structure1" /> 
</xsl:stylesheet>

The error line is indicated above.

Ken, could you please elaborate on what the built-in template rule is 
for the situation above? I read the XSLT 1.0 spec, but couldn't fully 
understand what it says.

Thanks,

-Farooq.
-- 
Mir Farooq Ali

Computer Science, Virginia Tech,
Email: miali(_at_)cs(_dot_)vt(_dot_)edu
Web: http://purl.org/net/farooq
--------------------------------------------
(c) 2004 Mir Farooq Ali  All rights reserved
--------------------------------------------


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



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



<Prev in Thread] Current Thread [Next in Thread>