xsl-list
[Top] [All Lists]

Re: [xsl] can a value of a parameter depends on a other value

2011-12-01 03:16:50
Hi Roelof,
    Here are couple of things I can see wrong in the stylesheet you've posted,

1. you've a variable declaration <xsl:variable name="mycount" ... but
you don't make use of this variable in the stylesheet.

2. you've a template definition
   <xsl:template match="artikel-details/entry">
      <xsl:param name="articleperpage"/>
      ...

which you're seemingly calling as,
<xsl:template match="/">
   <xsl:apply-templates select="/data/artikel-details/entry"/>
     ...

This is wrong, since you don't pass an argument matching the template
parameter. If you need a parameter in this template, then you should
call the template as follows,

<xsl:apply-templates select="/data/artikel-details/entry">
    <xsl:with-param name="articleperpage" select="{provide a value OR
compute}"/>
</xsl:apply-templates>

3. In the template definition,

<xsl:template match="artikel-details/entry">
  ...

you make a call to a named template as follows,

<xsl:call-template name="printdata">
   <xsl:with-param name="articleperpage">
     ...

To handle this template call, it seems you've defined this template,

<xsl:template match="printdata">
  ...

This seems to be wrong. I think, a xsl:template match=".. template
cannot receive a call from <xsl:call-template ... I think you need to
modify the template, <xsl:template match="printdata"> ... to
following,

<xsl:template name="printdata">
   <xsl:param name="articleperpage">
     ...

4. In the template call,

<xsl:call-template name="printdata">
     <xsl:with-param name="articleperpage">
         <xsl:choose>
             <xsl:when test="($month = '2005-02') and (number($page) =
1)">2</xsl:when>
             <xsl:when test="($month = '2005-02') and (number($page) =
2)">3</xsl:when>
             <otherwise>1</otherwise>
          </xsl:choose>
     </xsl:with-param>
</xsl:call-template>

you use variable references $month and $page. these variable
references were not declared before, which is wrong.

so lot of errors!

On Thu, Dec 1, 2011 at 1:45 PM, Roelof Wobben <rwobben(_at_)hotmail(_dot_)com> 
wrote:

Hello,



I tried your suggestion. See this :





<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

<xsl:output method="xml"
 doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
 doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";
 omit-xml-declaration="yes"
 encoding="UTF-8"
 indent="yes" />



<xsl:variable name="mycount" select="count(/data/artikel-details/entry)" />



<xsl:template match="/">
   <xsl:apply-templates select="/data/artikel-details/entry"/>
</xsl:template>



<xsl:template match="printdata">
  <h1><xsl:value-of select="titel"/></h1><br />
   <xsl:value-of select="datum" /><br />
   <xsl:value-of select="tekst" /> <br />
</xsl:template>



<xsl:template match="artikel-details/entry">
    <xsl:param name="articleperpage"/>

    <xsl:call-template name="printdata">
       <xsl:with-param name="articleperpage">
          <xsl:choose>
              <xsl:when test="($month = '2005-02') and (number($page) = 
1)">2</xsl:when>
               <xsl:when test="($month = '2005-02') and (number($page) = 
2)">3</xsl:when>
         <otherwise>1</otherwise>
        </xsl:choose>
    </xsl:with-param>
 </xsl:call-template>
</xsl:template>


</xsl:stylesheet>







But now I get a message that the called template printdata is not found.

What am I doing wrong here ?



Roelof




-- 
Regards,
Mukul Gandhi

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--