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 May 8th, 2006, 09:42 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 290
Thanks: 24
Thanked 0 Times in 0 Posts
Default

Hi Michael,

I was calling the template without using floor($x div 100) as you suggested.

I have corrected it now:

<xsl:template match="/">

    <select id="selDate">
      <xsl:call-template name="month-list">
         <xsl:with-param name="start" select="floor($firstDateTrans div 100)"/>
        <xsl:with-param name="end" select="floor($lastDateTrans div 100)"/>
      </xsl:call-template>
    </select>
  </xsl:template>

and I am using XMLSpy to debug it and I am getting the following output. It seems that the year is never changing and the text is not right either.

<select xmlns:d="data" id="selDate"><option value="2003.2">nFe</option><option value="2003.3">bMa</option><option value="2003.4">rAp</option><option value="2003.5">r..</option><option value="2003.6">.</option><option value="2003.7"></option><option value="2003.8"></option><option value="2003.9"></option><option value="2003.0"></option><option value="2003.1">Ja</option><option value="2003.2">nFe</option><option value="2003.3">bMa</option><option value="2003.4">rAp</option><option value="2003.5">r..</option><option value="2003.6">.</option><option value="2003.7"></option><option value="2003.8"></option><option value="2003.9"></option><option value="2003.0"></option><option value="2003.1">Ja</option><option value="2003.2">nFe</option><option value="2003.3">bMa</option><option value="2003.4">rAp</option><option value="2003.5">r..</option><option value="2003.6">.</option><option value="2003.7"></option><option value="2003.8"></option><option value="2003.9"></option><option value="2003.0"></option><option value="2003.1">Ja</option><option value="2003.2">nFe</option><option value="2003.3">bMa</option><option value="2003.4">rAp</option><option value="2003.5">r..</option><option value="2003.6">.</option><option value="2003.7"></option><option value="2003.8"></option><option value="2003.9"></option><option value="2003.0"></option><option value="2003.1">Ja</option><option /></select>


Could you please explain to me what this line does:

<xsl:value-of select="substring('JanFebMarApr...',($month - 1)*3, 3)"/>

Do I have to add the other months in the string like these for it to work?

'JanFebMarAprMayJunJulAugSepOctNovDec'

Sorry for my ignorance but I am not trying to abuse your good will I am just trying to learn and appreciate very much your help.

Cheers

CP





<select xmlns:d="data" id="selDate"><option value="2003.2">nFe</option><option value="2003.3">bMa</option><option value="2003.4">rAp</option><option value="2003.5">r..</option><option value="2003.6">.</option><option value="2003.7"></option><option value="2003.8"></option><option value="2003.9"></option><option value="2003.0"></option><option value="2003.1">Ja</option><option value="2003.2">nFe</option><option value="2003.3">bMa</option><option value="2003.4">rAp</option><option value="2003.5">r..</option><option value="2003.6">.</option><option value="2003.7"></option><option value="2003.8"></option><option value="2003.9"></option><option value="2003.0"></option><option value="2003.1">Ja</option><option value="2003.2">nFe</option><option value="2003.3">bMa</option><option value="2003.4">rAp</option><option value="2003.5">r..</option><option value="2003.6">.</option><option value="2003.7"></option><option value="2003.8"></option><option value="2003.9"></option><option value="2003.0"></option><option value="2003.1">Ja</option><option value="2003.2">nFe</option><option value="2003.3">bMa</option><option value="2003.4">rAp</option><option value="2003.5">r..</option><option value="2003.6">.</option><option value="2003.7"></option><option value="2003.8"></option><option value="2003.9"></option><option value="2003.0"></option><option value="2003.1">Ja</option><option /></select>



 
Old May 8th, 2006, 10:07 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

<xsl:value-of select="substring('JanFebMarApr...',($month - 1)*3, 3)"/>

Well, as the output shows it's off by one, it shouldbe

<xsl:value-of select="substring('JanFebMarApr...',($month - 1)*3 + 1, 3)"/>

and of course you were expected to fill in the rest of the months. If $month is 2 then then it takes a substring of 3 characters starting at position 4 which gives you "Feb". But you could use your Months lookup table if you prefer.

Your other problem seems to be that the months are numbered 0-11 rather than 1-12 which means $month=12 is never true.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old May 8th, 2006, 12:13 PM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 290
Thanks: 24
Thanked 0 Times in 0 Posts
Default

Michael,

Many many thanks to your help. I would like to express my sincere thanks to you.
Sorry but I will have to bother you once again. I am nearly getting there but there is a problem now. Because the last year(2005) finishes in September 200509 all the privious years are also finishing in September but they should carry on up to December.

2003 and 2004 are also being repeated and I don't know why.

This is the output I am getting:

<select id="selDate" xmlns:d="data"><option value="2003.2">Feb 2003</option>
<option value="2003.3">Mar 2003</option>
<option value="2003.4">Apr 2003</option>
<option value="2003.5">May 2003</option>
<option value="2003.6">Jun 2003</option>
<option value="2003.7">Jul 2003</option>
<option value="2003.8">Aug 2003</option>
<option value="2003.9">Sep 2003</option>
<option value="2003.0"> 2003</option>
<option value="2003.1">Jan 2003</option>
<option value="2003.2">Feb 2003</option>
<option value="2003.3">Mar 2003</option>
<option value="2003.4">Apr 2003</option>
<option value="2003.5">May 2003</option>
<option value="2003.6">Jun 2003</option>
<option value="2003.7">Jul 2003</option>
<option value="2003.8">Aug 2003</option>
<option value="2003.9">Sep 2003</option>
<option value="2003.0"> 2003</option>
<option value="2003.1">Jan 2003</option>
<option value="2003.2">Feb 2003</option>
<option value="2003.3">Mar 2003</option>
<option value="2003.4">Apr 2003</option>
<option value="2003.5">May 2003</option>
<option value="2003.6">Jun 2003</option>
<option value="2003.7">Jul 2003</option>
<option value="2003.8">Aug 2003</option>
<option value="2003.9">Sep 2003</option>
<option value="2003.0"> 2003</option>
<option value="2003.1">Jan 2003</option>
<option value="2003.2">Feb 2003</option>
<option value="2003.3">Mar 2003</option>
<option value="2003.4">Apr 2003</option>
<option value="2003.5">May 2003</option>
<option value="2003.6">Jun 2003</option>
<option value="2003.7">Jul 2003</option>
<option value="2003.8">Aug 2003</option>
<option value="2003.9">Sep 2003</option>
<option value="2003.0"> 2003</option>
<option value="2003.1">Jan 2003</option>
<option value="2003.2">Feb 2003</option>
<option value="2003.3">Mar 2003</option>
<option value="2003.4">Apr 2003</option>
<option value="2003.5">May 2003</option>
<option value="2003.6">Jun 2003</option>
<option value="2003.7">Jul 2003</option>
<option value="2003.8">Aug 2003</option>
<option value="2003.9">Sep 2003</option>
<option value="2003.0"> 2003</option>
<option value="2003.1">Jan 2003</option>
<option value="2003.2">Feb 2003</option>
<option value="2003.3">Mar 2003</option>
<option value="2003.4">Apr 2003</option>
<option value="2003.5">May 2003</option>
<option value="2003.6">Jun 2003</option>
<option value="2003.7">Jul 2003</option>
<option value="2003.8">Aug 2003</option>
<option value="2003.9">Sep 2003</option>
<option value="2003.0"> 2003</option>
<option value="2003.1">Jan 2003</option>
<option value="2003.2">Feb 2003</option>
<option value="2003.3">Mar 2003</option>
<option value="2003.4">Apr 2003</option>
<option value="2003.5">May 2003</option>
<option value="2003.6">Jun 2003</option>
<option value="2003.7">Jul 2003</option>
<option value="2003.8">Aug 2003</option>
<option value="2003.9">Sep 2003</option>
<option value="2003.0"> 2003</option>
<option value="2003.1">Jan 2003</option>
<option value="2003.2">Feb 2003</option>
<option value="2003.3">Mar 2003</option>
<option value="2003.4">Apr 2003</option>
<option value="2003.5">May 2003</option>
<option value="2003.6">Jun 2003</option>
<option value="2003.7">Jul 2003</option>
<option value="2003.8">Aug 2003</option>
<option value="2003.9">Sep 2003</option>
<option value="2003.0"> 2003</option>
<option value="2003.1">Jan 2003</option>
<option value="2003.2">Feb 2003</option>
<option value="2003.3">Mar 2003</option>
<option value="2003.4">Apr 2003</option>
<option value="2003.5">May 2003</option>
<option value="2003.6">Jun 2003</option>
<option value="2003.7">Jul 2003</option>
<option value="2003.8">Aug 2003</option>
<option value="2003.9">Sep 2003</option>
<option value="2003.0"> 2003</option>
<option value="2003.1">Jan 2003</option>
<option value="2003.2">Feb 2003</option>
<option value="2003.3">Mar 2003</option>
<option value="2003.4">Apr 2003</option>
<option value="2003.5">May 2003</option>
<option value="2003.6">Jun 2003</option>
<option value="2003.7">Jul 2003</option>
<option value="2003.8">Aug 2003</option>
<option value="2003.9">Sep 2003</option>
<option value="2004.0"> 2004</option>
<option value="2004.1">Jan 2004</option>
<option value="2004.2">Feb 2004</option>
<option value="2004.3">Mar 2004</option>
<option value="2004.4">Apr 2004</option>
<option value="2004.5">May 2004</option>
<option value="2004.6">Jun 2004</option>
<option value="2004.7">Jul 2004</option>
<option value="2004.8">Aug 2004</option>
<option value="2004.9">Sep 2004</option>
<option value="2004.0"> 2004</option>
<option value="2004.1">Jan 2004</option>
<option value="2004.2">Feb 2004</option>
<option value="2004.3">Mar 2004</option>
<option value="2004.4">Apr 2004</option>
<option value="2004.5">May 2004</option>
<option value="2004.6">Jun 2004</option>
<option value="2004.7">Jul 2004</option>
<option value="2004.8">Aug 2004</option>
<option value="2004.9">Sep 2004</option>
<option value="2004.0"> 2004</option>
<option value="2004.1">Jan 2004</option>
<option value="2004.2">Feb 2004</option>
<option value="2004.3">Mar 2004</option>
<option value="2004.4">Apr 2004</option>
<option value="2004.5">May 2004</option>
<option value="2004.6">Jun 2004</option>
<option value="2004.7">Jul 2004</option>
<option value="2004.8">Aug 2004</option>
<option value="2004.9">Sep 2004</option>
<option value="2004.0"> 2004</option>
<option value="2004.1">Jan 2004</option>
<option value="2004.2">Feb 2004</option>
<option value="2004.3">Mar 2004</option>
<option value="2004.4">Apr 2004</option>
<option value="2004.5">May 2004</option>
<option value="2004.6">Jun 2004</option>
<option value="2004.7">Jul 2004</option>
<option value="2004.8">Aug 2004</option>
<option value="2004.9">Sep 2004</option>
<option value="2004.0"> 2004</option>
<option value="2004.1">Jan 2004</option>
<option value="2004.2">Feb 2004</option>
<option value="2004.3">Mar 2004</option>
<option value="2004.4">Apr 2004</option>
<option value="2004.5">May 2004</option>
<option value="2004.6">Jun 2004</option>
<option value="2004.7">Jul 2004</option>
<option value="2004.8">Aug 2004</option>
<option value="2004.9">Sep 2004</option>
<option value="2004.0"> 2004</option>
<option value="2004.1">Jan 2004</option>
<option value="2004.2">Feb 2004</option>
<option value="2004.3">Mar 2004</option>
<option value="2004.4">Apr 2004</option>
<option value="2004.5">May 2004</option>
<option value="2004.6">Jun 2004</option>
<option value="2004.7">Jul 2004</option>
<option value="2004.8">Aug 2004</option>
<option value="2004.9">Sep 2004</option>
<option value="2004.0"> 2004</option>
<option value="2004.1">Jan 2004</option>
<option value="2004.2">Feb 2004</option>
<option value="2004.3">Mar 2004</option>
<option value="2004.4">Apr 2004</option>
<option value="2004.5">May 2004</option>
<option value="2004.6">Jun 2004</option>
<option value="2004.7">Jul 2004</option>
<option value="2004.8">Aug 2004</option>
<option value="2004.9">Sep 2004</option>
<option value="2004.0"> 2004</option>
<option value="2004.1">Jan 2004</option>
<option value="2004.2">Feb 2004</option>
<option value="2004.3">Mar 2004</option>
<option value="2004.4">Apr 2004</option>
<option value="2004.5">May 2004</option>
<option value="2004.6">Jun 2004</option>
<option value="2004.7">Jul 2004</option>
<option value="2004.8">Aug 2004</option>
<option value="2004.9">Sep 2004</option>
<option value="2004.0"> 2004</option>
<option value="2004.1">Jan 2004</option>
<option value="2004.2">Feb 2004</option>
<option value="2004.3">Mar 2004</option>
<option value="2004.4">Apr 2004</option>
<option value="2004.5">May 2004</option>
<option value="2004.6">Jun 2004</option>
<option value="2004.7">Jul 2004</option>
<option value="2004.8">Aug 2004</option>
<option value="2004.9">Sep 2004</option>
<option value="2004.0"> 2004</option>
<option value="2004.1">Jan 2004</option>
<option value="2004.2">Feb 2004</option>
<option value="2004.3">Mar 2004</option>
<option value="2004.4">Apr 2004</option>
<option value="2004.5">May 2004</option>
<option value="2004.6">Jun 2004</option>
<option value="2004.7">Jul 2004</option>
<option value="2004.8">Aug 2004</option>
<option value="2004.9">Sep 2004</option>
<option value="2005.0"> 2005</option>
<option value="2005.1">Jan 2005</option>
<option value="2005.2">Feb 2005</option>
<option value="2005.3">Mar 2005</option>
<option value="2005.4">Apr 2005</option>
<option value="2005.5">May 2005</option>
<option value="2005.6">Jun 2005</option>
<option value="2005.7">Jul 2005</option>
<option value="2005.8">Aug 2005</option>
<option value="2005.9">Sep 2005</option></select>

 
Old May 8th, 2006, 12:25 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Looks like the month should be substring(x,5,2) not substring(x,6,2). Alternatively, take the month as $start mod 100.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old May 8th, 2006, 12:27 PM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 290
Thanks: 24
Thanked 0 Times in 0 Posts
Default

Sorry I forgot to send the latest XSLT

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:d="data">
<xsl:output method="html" indent="yes"/>


  <xsl:variable name ="firstDateTrans">
    <xsl:apply-templates select ="Products" mode ="tran1" />
  </xsl:variable>

  <xsl:variable name ="lastDateTrans">
    <xsl:apply-templates select ="Products" mode ="tran2" />
  </xsl:variable>

  <xsl:template match="/">

    <select id="selDate">
      <xsl:call-template name="month-list">
         <xsl:with-param name="start" select="floor($firstDateTrans div 100)"/>
        <xsl:with-param name="end" select="floor($lastDateTrans div 100)"/>
      </xsl:call-template>
    </select>
  </xsl:template>

  <xsl:template name="month-list">
    <xsl:param name="start"/>
    <xsl:param name="end"/>
    <xsl:if test="$start &lt;= $end">
      <xsl:variable name="year" select="substring($start,1,4)"/>
      <xsl:variable name="month" select="number(substring($start, 6, 2))"/>
      <option value="{concat($year, '.', $month)}">
        <xsl:value-of select="concat(substring('JanFebMarAprMayJunJulAug SepOctNovDec',($month - 1)*3+1, 3), ' ', $year)"/>
      </option>

      <xsl:variable name="next-month">
        <xsl:choose>
          <xsl:when test="$month=12">
            <xsl:value-of select="($year+1)*100 + 1"/>
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="$start + 1"/>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:variable>

      <xsl:call-template name="month-list">
        <xsl:with-param name="start" select="$next-month"/>
        <xsl:with-param name="end" select="$end"/>
      </xsl:call-template>
      </xsl:if>
  </xsl:template>




  <xsl:template match ="Products" mode ="tran2">
    <xsl:for-each select ="Product">
      <xsl:sort select ="@lastIns" order="ascending" data-type="text"/>
      <xsl:if test ="position()=last()">
        <xsl:value-of select ="number(translate(@lastIns, '-', ''))"/>
      </xsl:if>
    </xsl:for-each>
  </xsl:template>

  <xsl:template match ="Products" mode ="tran1">
    <xsl:for-each select ="Product">
      <xsl:sort select ="@firsIns" order="ascending" data-type="text"/>
      <xsl:if test ="position()=1">
        <xsl:value-of select ="number(translate(@firsIns, '-', ''))"/>
      </xsl:if>
    </xsl:for-each>

  </xsl:template>


</xsl:stylesheet>


And this is the XML


<Products>
  <Product prodID="PRD0099" name="Azasan" class="Transplant/Immunosupp" company="Aai Pharma" firsIns="2003-03-01" lastIns="2004-12-31" />
  <Product prodID="PRD0215" name="Darvocet A500" class="Propoxyphenes" company="Aai Pharma" firsIns="2003-02-01" lastIns="2005-09-30" />
</Products>



 
Old May 8th, 2006, 12:41 PM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 290
Thanks: 24
Thanked 0 Times in 0 Posts
Default

Michael,

AS you suggested I changed this line:
<xsl:variable name="month" select="number(substring($start, 6, 2))"/>
with this:
 <xsl:variable name="month" select="number(substring($start, 5, 2))"/>

and I think it is working now. Wow many thanks indeed.

I will try to change my xml now to see if it will change with different dates.

you are super. Thanks !!!






Similar Threads
Thread Thread Starter Forum Replies Last Post
Select range node Christ M XSLT 4 January 25th, 2008 12:47 PM
How to find a date range between another date rang tayvonne Access 2 August 3rd, 2006 09:50 AM
Need Help With Date Range rpainter Crystal Reports 0 June 20th, 2005 01:01 PM
Help with Date Range PacMed Access 1 February 1st, 2005 12:30 PM
Date Range mrideout BOOK: Beginning ASP.NET 1.0 0 January 2nd, 2005 07:18 PM





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