Problem with recursive template

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Problem with recursive template

Brendan.McKenna
Hi all,

        I have the following template:

    <xsl:template name='make-multi-key-string'>
        <xsl:param name='pos'/>
        <xsl:param name='crumbs'/>
        <xsl:param name='cur-string'/>
        <xsl:choose>
            <xsl:when test='$pos gt count($crumbs/a5:hierarchyLevel)'>
                <!-- We're through - return the string -->
                <xsl:value-of select='$cur-string'/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:variable name='next-bit'>
                    <xsl:apply-templates
                        select='$crumbs/a5:hierarchyLevel[position() eq
$pos]'
                        mode='key-string'/>
                </xsl:variable>
                <xsl:call-template name='make-multi-key-string'>
                    <xsl:with-param name='pos' select='$pos +1'/>
                    <xsl:with-param name='crumbs' select='$crumbs'/>
                    <xsl:with-param name='cur-string'>
                        <xsl:choose>
                            <xsl:when test='$pos eq 1'>
                                <xsl:value-of select='$next-bit'/>
                            </xsl:when>
                            <xsl:otherwise>
                                <!--xsl:value-of
select='concat(concat($cur-string,"|"),$next-bit)'/-->
                                <xsl:value-of
select='string-join(($cur-string, $next-bit),"|")'/>
                            </xsl:otherwise>
                        </xsl:choose>
                    </xsl:with-param>
                </xsl:call-template>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>

        Which is causing me no end of trouble.

        When I call it with two (or more) a5:hierarchyLevel elements in
the 'crumbs' parameter, I get the concatenated string that I expect,
however all of the separators that I want between the strings appear at
the end of the concatenated strings, and not 'mixed in' between the
individual strings as I would expect.  The template is called with the pos
parameter set to number(1), and with cur-string set to an empty string.  I
am able to verify that the template being called to defined the $next-bit
variable is working fine (since the strings I expect are being produced
correctly, just not separated from eachother as I'd expect).

        I expect that there's something basic that I'm just not
understanding, but I figure I've been pounding my head against the wall
long enough to ask for help!  Any assistance would be greatly appreciated.


                        Thanks,

                                Brendan


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
saxon-help mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help
Reply | Threaded
Open this post in threaded view
|

Re: Problem with recursive template

Brendan.McKenna
        Oops!  Sorry, I forgot to mention that I'm using Saxon 8.6.1 (on
Windows XP, if that makes a difference).


                                Brendan


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
saxon-help mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help
Reply | Threaded
Open this post in threaded view
|

RE: Problem with recursive template

Michael Kay
In reply to this post by Brendan.McKenna
I made some trivial changes just to enable me to run this, and it's working
for me. That suggests the problem is in your initial call. Please supply a
complete working example including a full stylesheet and source document,
indicating the output you expect and the output you are getting.

However, please also note that this list is not the right place to ask for
XSLT coding help: you should really be going to xsl-list at mulberrytech.com
for that, as there's nothing here that indicates a Saxon-specific problem.

Michael Kay
http://www.saxonica.com/ 

> -----Original Message-----
> From: [hidden email]
> [mailto:[hidden email]] On Behalf Of
> [hidden email]
> Sent: 21 December 2005 16:37
> To: [hidden email]
> Subject: [saxon] Problem with recursive template
>
> Hi all,
>
>         I have the following template:
>
>     <xsl:template name='make-multi-key-string'>
>         <xsl:param name='pos'/>
>         <xsl:param name='crumbs'/>
>         <xsl:param name='cur-string'/>
>         <xsl:choose>
>             <xsl:when test='$pos gt count($crumbs/a5:hierarchyLevel)'>
>                 <!-- We're through - return the string -->
>                 <xsl:value-of select='$cur-string'/>
>             </xsl:when>
>             <xsl:otherwise>
>                 <xsl:variable name='next-bit'>
>                     <xsl:apply-templates
>                        
> select='$crumbs/a5:hierarchyLevel[position() eq
> $pos]'
>                         mode='key-string'/>
>                 </xsl:variable>
>                 <xsl:call-template name='make-multi-key-string'>
>                     <xsl:with-param name='pos' select='$pos +1'/>
>                     <xsl:with-param name='crumbs' select='$crumbs'/>
>                     <xsl:with-param name='cur-string'>
>                         <xsl:choose>
>                             <xsl:when test='$pos eq 1'>
>                                 <xsl:value-of select='$next-bit'/>
>                             </xsl:when>
>                             <xsl:otherwise>
>                                 <!--xsl:value-of
> select='concat(concat($cur-string,"|"),$next-bit)'/-->
>                                 <xsl:value-of
> select='string-join(($cur-string, $next-bit),"|")'/>
>                             </xsl:otherwise>
>                         </xsl:choose>
>                     </xsl:with-param>
>                 </xsl:call-template>
>             </xsl:otherwise>
>         </xsl:choose>
>     </xsl:template>
>
>         Which is causing me no end of trouble.
>
>         When I call it with two (or more) a5:hierarchyLevel
> elements in
> the 'crumbs' parameter, I get the concatenated string that I expect,
> however all of the separators that I want between the strings
> appear at
> the end of the concatenated strings, and not 'mixed in' between the
> individual strings as I would expect.  The template is called
> with the pos
> parameter set to number(1), and with cur-string set to an
> empty string.  I
> am able to verify that the template being called to defined
> the $next-bit
> variable is working fine (since the strings I expect are
> being produced
> correctly, just not separated from eachother as I'd expect).
>
>         I expect that there's something basic that I'm just not
> understanding, but I figure I've been pounding my head
> against the wall
> long enough to ask for help!  Any assistance would be greatly
> appreciated.
>
>
>                         Thanks,
>
>                                 Brendan
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: Splunk Inc. Do you grep
> through log files
> for problems?  Stop!  Download the new AJAX search engine that makes
> searching your log files as easy as surfing the  web.  
> DOWNLOAD SPLUNK!
> http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
> _______________________________________________
> saxon-help mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/saxon-help
>




-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
saxon-help mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help
Reply | Threaded
Open this post in threaded view
|

RE: Problem with recursive template

Michael Kay
In reply to this post by Brendan.McKenna
Your data (sent off-list) shows that $crumbs is a set of elements each of
which has one a5:hierarchyLevel child. Therefore

$crumbs/a5:hierarchyLevel[position() eq $pos]

selects nothing unless $pos = 1, in which case it selects all the
a5:hierarchyLevel elements.

You should have written

$crumbs[position() eq $pos]/a5:hierarchyLevel

(I found this very quickly by adding an xsl:message trace that displayed the
value of the $next-bit variable)

Michael Kay
http://www.saxonica.com/



> -----Original Message-----
> From: [hidden email]
> [mailto:[hidden email]] On Behalf Of
> [hidden email]
> Sent: 21 December 2005 16:37
> To: [hidden email]
> Subject: [saxon] Problem with recursive template
>
> Hi all,
>
>         I have the following template:
>
>     <xsl:template name='make-multi-key-string'>
>         <xsl:param name='pos'/>
>         <xsl:param name='crumbs'/>
>         <xsl:param name='cur-string'/>
>         <xsl:choose>
>             <xsl:when test='$pos gt count($crumbs/a5:hierarchyLevel)'>
>                 <!-- We're through - return the string -->
>                 <xsl:value-of select='$cur-string'/>
>             </xsl:when>
>             <xsl:otherwise>
>                 <xsl:variable name='next-bit'>
>                     <xsl:apply-templates
>                        
> select='$crumbs/a5:hierarchyLevel[position() eq
> $pos]'
>                         mode='key-string'/>
>                 </xsl:variable>
>                 <xsl:call-template name='make-multi-key-string'>
>                     <xsl:with-param name='pos' select='$pos +1'/>
>                     <xsl:with-param name='crumbs' select='$crumbs'/>
>                     <xsl:with-param name='cur-string'>
>                         <xsl:choose>
>                             <xsl:when test='$pos eq 1'>
>                                 <xsl:value-of select='$next-bit'/>
>                             </xsl:when>
>                             <xsl:otherwise>
>                                 <!--xsl:value-of
> select='concat(concat($cur-string,"|"),$next-bit)'/-->
>                                 <xsl:value-of
> select='string-join(($cur-string, $next-bit),"|")'/>
>                             </xsl:otherwise>
>                         </xsl:choose>
>                     </xsl:with-param>
>                 </xsl:call-template>
>             </xsl:otherwise>
>         </xsl:choose>
>     </xsl:template>
>
>         Which is causing me no end of trouble.
>
>         When I call it with two (or more) a5:hierarchyLevel
> elements in
> the 'crumbs' parameter, I get the concatenated string that I expect,
> however all of the separators that I want between the strings
> appear at
> the end of the concatenated strings, and not 'mixed in' between the
> individual strings as I would expect.  The template is called
> with the pos
> parameter set to number(1), and with cur-string set to an
> empty string.  I
> am able to verify that the template being called to defined
> the $next-bit
> variable is working fine (since the strings I expect are
> being produced
> correctly, just not separated from eachother as I'd expect).
>
>         I expect that there's something basic that I'm just not
> understanding, but I figure I've been pounding my head
> against the wall
> long enough to ask for help!  Any assistance would be greatly
> appreciated.
>
>
>                         Thanks,
>
>                                 Brendan
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: Splunk Inc. Do you grep
> through log files
> for problems?  Stop!  Download the new AJAX search engine that makes
> searching your log files as easy as surfing the  web.  
> DOWNLOAD SPLUNK!
> http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
> _______________________________________________
> saxon-help mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/saxon-help
>




-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
saxon-help mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help