Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 17th, 2005, 01:03 PM
wu4 wu4 is offline
Registered User
 
Join Date: Oct 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Help for named template

I am writing a xslt template named inList. It has 3 params. list, name, return value.

I use it to check if any member of list has name attribute $name.
I don't know why following code doesn't work. Hope someone can help me.

Thanks

Code:
 <xsl:template name="inList">
    <xsl:param name="list"/>
    <xsl:param name="name"/>
    <xsl:param name="returnValue"/>

    <xsl:choose>

      <xsl:when test="list">



        <xsl:variable name="remainingList" select="$list[position() != 1]" />

        <xsl:variable name="newValue">
          <xsl:choose>

          <xsl:when test="$list[1]=$name">
            number($returnValue)+1
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="$returnValue"/>
          </xsl:otherwise>

          </xsl:choose>
        </xsl:variable>



        <xsl:call-template name="inList">
          <xsl:with-param name="list" select="$remainingList"/>
          <xsl:with-param name="name" select="$name"/>
          <xsl:with-param name="returnValue" select="$newValue"/>
        </xsl:call-template>


      </xsl:when>


      <xsl:otherwise>
        <xsl:value-of select="$returnValue"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
 
Old October 17th, 2005, 01:51 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Need to see how you're calling this: the calling template in the stylesheet, and the source document.

You don't say what value you're trying to return when the name is found.

This code looks very peculiar:

          <xsl:when test="$list[1]=$name">
            number($returnValue)+1
          </xsl:when>

Did you mean to write

          <xsl:when test="$list[1]=$name">
            <xsl:value-of select="number($returnValue)+1"/>
          </xsl:when>

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old October 18th, 2005, 10:09 AM
wu4 wu4 is offline
Registered User
 
Join Date: Oct 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The template inList is called here.
Actually, my purpose is to get class hierarchy from doxgen xml output.
I want to know, what parameter can be for a named template. can it be a tree, can any one give me an example.

Code:
<xsl:variable name="rootclasseswithoutchildren">
  <classes>
    <xsl:for-each select="saxon:node-set($classes)/classes/class[not(subclass)]">
      <xsl:variable name="myname">
        <xsl:value-of select="@name"/>
      </xsl:variable>
      <xsl:variable name="nInList">
        <xsl:call-template name="inList">
          <xsl:with-param name="list" select="saxon:node-set($classes)/classes/class/subclass"/>
          <xsl:with-param name="name" select="$myname"/>  
          <xsl:with-param name="returnValue" select="'0'"/>
        </xsl:call-template>
      </xsl:variable>
      <xsl:if test="number($nInList)=0">
        <xsl:copy-of select="."/>
      </xsl:if>
    </xsl:for-each>
  </classes>





Similar Threads
Thread Thread Starter Forum Replies Last Post
Named template being called, to no effect (newb) sardaukar XSLT 2 June 22nd, 2007 07:40 AM
Connecting to a named instance mjhoagland SQL Server 2000 3 January 2nd, 2007 08:48 AM
named anchors stekker XSLT 1 November 16th, 2006 05:03 AM
Named arguments Bob Bedell C# 2 March 19th, 2006 09:25 PM
Named Pipes bpe_xmind Visual C++ 0 February 5th, 2006 08:21 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.