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 April 22nd, 2009, 03:09 PM
Authorized User
 
Join Date: Oct 2008
Posts: 26
Thanks: 2
Thanked 0 Times in 0 Posts
Default Bizarre record dropping issue

For some weird reason my xslt is causing random records to NOT display because of certain date values. For instance September 23 & September 25 will show up, but if I change the date to September 24, it drops. It's completely random as to which dates will show up and which ones won't. What is it I'm doing wrong?

Date within the xml file is done in YYYYMMDD format. Here's the date display format in XSL:

Code:
 
<xsl:template name="format-date">
<xsl:variable name="d"><xsl:value-of select="../docdate" /></xsl:variable>
<xsl:call-template name="long_date"><xsl:with-param name="date" select="$d" /></xsl:call-template>
</xsl:template>
<xsl:template name="long_date">
<xsl:param name="date" />
<xsl:value-of select="substring($date, 7, 2)" /> 
<xsl:variable name="month" select="substring($date, 5, 2)" />
<xsl:choose>
<xsl:when test="$month=01">January</xsl:when>
<xsl:when test="$month=02">February</xsl:when>
<xsl:when test="$month=03">March</xsl:when>
<xsl:when test="$month=04">April</xsl:when>
<xsl:when test="$month=05">May</xsl:when>
<xsl:when test="$month=06">June</xsl:when>
<xsl:when test="$month=07">July</xsl:when>
<xsl:when test="$month=08">August</xsl:when>
<xsl:when test="$month=09">September</xsl:when>
<xsl:when test="$month=10">October</xsl:when>
<xsl:when test="$month=11">November</xsl:when>
<xsl:when test="$month=12">December</xsl:when>
<xsl:otherwise>INVALID MONTH</xsl:otherwise>
</xsl:choose> 
<xsl:value-of select="substring($date, 1, 4)" />
</xsl:template>
I can send the other parts of the XSL as well, but the whole is a bit long and this is the only part that seems to have trouble. Let me know if you need that too. Thanks so much for any help.
 
Old April 22nd, 2009, 03:17 PM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Consider to provide a minimal but complete XML input document and XSLT stylesheet that allows us to reproduce the problem.
And tell us which XSLT processor you use.
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
 
Old April 22nd, 2009, 03:18 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

I'm 99% sure that the bug is not in the piece of code that you have shown us.

The only thing I can therefore tell you about it is that it is elsewhere.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old April 22nd, 2009, 05:02 PM
Authorized User
 
Join Date: Oct 2008
Posts: 26
Thanks: 2
Thanked 0 Times in 0 Posts
Default

A sample part of the XML, which is about 239kb in size:

Code:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<downloads>
   <item category="meeting">
     <program id="board"> Board of Directors</program>
     <docdate>20080827</docdate>
     <title>Executive Committee Meeting</title>
     <desc>Executive Committee Meeting</desc>
     <xref>ftp://ftp.cog.org/pub/cog/minutes/200808_exec.pdf</xref>
     <docformat>PDF</docformat>
     <docsize>
        <mb>1</mb>
        <kb>21</kb>
     </docsize>
     <comment></comment>
     <postdate>20090415</postdate>
  </item> 
  <item category="meeting">
     <program id="board"> Board of Directors</program>
     <docdate>20080925</docdate>
     <title>Board of Directors Meeting</title>
     <desc>Board of Directors Meeting</desc>
     <xref>ftp://ftp.cog.org/pub/cog/minutes/200809_bod.pdf</xref>
     <docformat>PDF</docformat>
     <docsize>
        <mb></mb>
        <kb>714</kb>
     </docsize>
     <comment></comment>
     <postdate>20090415</postdate>
  </item>
</downloads>
A part of the XSL:

Code:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xdt="http://www.w3.org/2005/02/xpath-datatypes">
<xsl:key name="sortdate" match="item" use="docdate"/>
<xsl:param name="project"></xsl:param>
<xsl:if test="//downloads/item[@category='meeting' or @category='agenda' or @category='summary']/program[@id=$project]">
<xsl:element name="h3">
<xsl:attribute name="class">sidebar</xsl:attribute> 
Meeting Information
</xsl:element> 
<xsl:element name="p">
<xsl:attribute name="style">margin: -8px 0 0 0; font-size: .9em; font-style: italic; color: #887</xsl:attribute>
(click on date to view documents)
</xsl:element>
<xsl:for-each select="//downloads/item[@category='meeting' or @category='agenda' or @category='summary']/program[@id=$project][generate-id(..)=generate-id(key('sortdate', ../docdate)[1])]">
<xsl:sort select="../docdate" order="descending" data-type="number"/>
<xsl:variable name="myid" select="../docdate"/>
<xsl:element name="a">
<xsl:attribute name="style">font-weight: bold</xsl:attribute> 
<xsl:attribute name="href">javascript:toggleDiv('<xsl:value-of select="$myid"/>')</xsl:attribute>
<xsl:element name="h4"> 
<xsl:call-template name="format-date"/>
</xsl:element>
</xsl:element>
 
<xsl:element name="div">
<xsl:attribute name="id"><xsl:value-of select="$myid"/></xsl:attribute>
<xsl:attribute name="style">display:none; margin-bottom: 10px</xsl:attribute>
<xsl:element name="table">
 
 
<xsl:for-each select="key('sortdate', ../docdate)"> 
<xsl:if test="position() mod 2 = 1">
<xsl:element name="tr">
<xsl:attribute name="style">background-color: #fff; border: 0</xsl:attribute>
<xsl:element name="td">
<xsl:attribute name="style">padding: 3px</xsl:attribute>
<xsl:element name="a">
<xsl:attribute name="href"><xsl:value-of select="xref"/></xsl:attribute>
<xsl:value-of select="title"/>
</xsl:element>
<xsl:if test="docsize/mb != ''">
 <xsl:element name="small">
<xsl:value-of select="docsize/mb"/>.<xsl:value-of select="docsize/kb"/>Mb
</xsl:element>
</xsl:if>
<xsl:call-template name="otrfmt"/>
<xsl:if test="comment != ''">
<xsl:element name="br"/>
<xsl:element name="small"> 
<xsl:value-of select="comment"/>
</xsl:element>
</xsl:if>
</xsl:element> 
</xsl:element>
</xsl:if>
<xsl:if test="position() mod 2 = 0">
<xsl:element name="tr">
<xsl:attribute name="style">background-color: #ede5df; border: 0</xsl:attribute>
<xsl:element name="td">
<xsl:attribute name="style">padding: 3px</xsl:attribute>
<xsl:element name="a">
<xsl:attribute name="href"><xsl:value-of select="xref"/></xsl:attribute>
<xsl:value-of select="title"/>
</xsl:element>
<xsl:if test="docsize/mb != ''">
 <xsl:element name="small">
<xsl:value-of select="docsize/mb"/>.<xsl:value-of select="docsize/kb"/>Mb
</xsl:element>
</xsl:if>
<xsl:call-template name="otrfmt"/>
<xsl:if test="comment != ''">
<xsl:element name="br"/>
<xsl:element name="small"> 
<xsl:value-of select="comment"/>
</xsl:element>
</xsl:if>
</xsl:element> 
</xsl:element>
</xsl:if> 
</xsl:for-each>
 
</xsl:element>
</xsl:element>
 
</xsl:for-each> 
</xsl:if>
 
Old April 22nd, 2009, 07:29 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

As Martin said, you need to produce a sample of XML and XSLT that are small enough to post but complete so that other people can run them and see if they get the same problem, and if so, try to debug it for you. This is obviously a pretty obscure problem and it's unlikely that you're looking in the right place for it, so we need to have a repro if we're to help you. Also, Martin asked you what processor you're using - he asked for a reason, so please answer.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old April 28th, 2009, 10:44 AM
Authorized User
 
Join Date: Oct 2008
Posts: 26
Thanks: 2
Thanked 0 Times in 0 Posts
Default

This is a client-side process.

The XML is all pretty much as the sample I gave before, only the dates differ depending upon the meeting, but here is that sample again:

Code:
 
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<downloads>
   <item category="meeting">
     <program id="board"> Board of Directors</program>
     <docdate>20080827</docdate>
     <title>Executive Committee Meeting</title>
     <desc>Executive Committee Meeting</desc>
     <xref>ftp://ftp.cog.org/pub/cog/minutes/200808_exec.pdf</xref>
     <docformat>PDF</docformat>
     <docsize>
        <mb>1</mb>
        <kb>21</kb>
     </docsize>
     <comment></comment>
     <postdate>20090415</postdate>
  </item> 
  <item category="meeting">
     <program id="board"> Board of Directors</program>
     <docdate>20080925</docdate>
     <title>Board of Directors Meeting</title>
     <desc>Board of Directors Meeting</desc>
     <xref>ftp://ftp.cog.org/pub/cog/minutes/200809_bod.pdf</xref>
     <docformat>PDF</docformat>
     <docsize>
        <mb></mb>
        <kb>714</kb>
     </docsize>
     <comment></comment>
     <postdate>20090415</postdate>
  </item>
</downloads>
The XSL is quite a bit longer. I don't know what else to give you besides reprinting the whole of it, which is long:

Code:
 
<?xml version="1.0" encoding="utf-8"?> 
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xdt="http://www.w3.org/2005/02/xpath-datatypes">
<xsl:key name="sortdate" match="item" use="docdate"/>
<xsl:param name="project"></xsl:param> 
 
<xsl:template match="/" name="main">
   <xsl:if test="//downloads/item/program[@id=$project]"> 
       <xsl:element name="h1">
            <xsl:attribute name="class">side</xsl:attribute> 
             DOWNLOADS
       </xsl:element>
 
 
   <xsl:if test="//downloads/item[@category='general']/program[@id=$project] or //downloads/item[@category='brochure']/program[@id=$project]">
       <xsl:element name="h3">
          <xsl:attribute name="class">sidebar</xsl:attribute> 
          General Information
       </xsl:element> 
       <xsl:element name="table">
          <xsl:attribute name="style">margin: -8px 0 10px 0; padding: 0; border: 0; font: 500 'Trebuchet MS', helvetica, sans-serif; width:98%</xsl:attribute>
          <xsl:for-each select="//downloads/item[@category='general' or @category='brochure']/program[@id=$project]">
              <xsl:sort select="../docdate" order="descending" data-type="number" />
             <xsl:call-template name="populate" />
          </xsl:for-each> 
       </xsl:element>
   </xsl:if>
 
   <xsl:if test="//downloads/item[@category='forms']/program[@id=$project]">
       <xsl:element name="h3">
          <xsl:attribute name="class">sidebar</xsl:attribute> 
          Forms
       </xsl:element>
       <xsl:element name="table">
          <xsl:attribute name="style">margin: -8px 0 10px 0; padding: 0; border: 0; font: 500 'Trebuchet MS', helvetica, sans-serif; width:98%</xsl:attribute>
          <xsl:for-each select="//downloads/item[@category='forms']/program[@id=$project]">
             <xsl:sort select="../docdate" order="descending" data-type="number" />
             <xsl:call-template name="populate" />
          </xsl:for-each> 
       </xsl:element>
   </xsl:if> 
   <xsl:if test="//downloads/item[@category='audit']/program[@id=$project]">
       <xsl:element name="h3">
           <xsl:attribute name="class">sidebar</xsl:attribute> 
           Annual Audits
       </xsl:element>
       <xsl:element name="table">
          <xsl:attribute name="style">margin: -8px 0 10px 0; padding: 0; border: 0; font: 500 'Trebuchet MS', helvetica, sans-serif; width:98%</xsl:attribute>
          <xsl:for-each select="//downloads/item[@category='audit']/program[@id=$project]">
             <xsl:sort select="../docdate" order="descending" data-type="number" />
             <xsl:call-template name="populate" />
           </xsl:for-each> 
       </xsl:element>
   </xsl:if>
   <xsl:if test="//downloads/item[@category='budget']/program[@id=$project]">
       <xsl:element name="h3">
          <xsl:attribute name="class">sidebar</xsl:attribute> 
          Annual Budgets
       </xsl:element>
       <xsl:element name="table">
          <xsl:attribute name="style">margin: -8px 0 10px 0; padding: 0; border: 0; font: 500 'Trebuchet MS', helvetica, sans-serif; width:98%</xsl:attribute>
          <xsl:for-each select="//downloads/item[@category='budget']/program[@id=$project]">
             <xsl:sort select="../docdate" order="descending" data-type="number" />
             <xsl:call-template name="populate" />
          </xsl:for-each> 
       </xsl:element>
   </xsl:if>
   <xsl:if test="//downloads/item[@category='rfp']/program[@id=$project]">
       <xsl:element name="h3">
          <xsl:attribute name="class">sidebar</xsl:attribute> 
          Requests for Proposals
       </xsl:element>
       <xsl:element name="table">
          <xsl:attribute name="style">margin: -8px 0 10px 0; padding: 0; border: 0; font: 500 'Trebuchet MS', helvetica, sans-serif; width:98%</xsl:attribute>
          <xsl:for-each select="//downloads/item[@category='rfp']/program[@id=$project]">
             <xsl:sort select="../docdate" order="descending" data-type="number" />
             <xsl:call-template name="populate" />
          </xsl:for-each> 
       </xsl:element>
    </xsl:if>
 
    <xsl:if test="//downloads/item[@category='meeting' or @category='agenda' or @category='summary']/program[@id=$project]">
       <xsl:element name="h3">
          <xsl:attribute name="class">sidebar</xsl:attribute> 
          Meeting Information
       </xsl:element> 
       <xsl:element name="p">
          <xsl:attribute name="style">margin: -8px 0 0 0; font-size: .9em; font-style: italic; color: #887</xsl:attribute>
          (click on date to view documents)
       </xsl:element>
       <xsl:for-each select="//downloads/item[@category='meeting' or @category='agenda' or @category='summary']/program[@id=$project][generate-id(..)=generate-id(key('sortdate', ../docdate)[1])]">
          <xsl:sort select="../docdate" order="descending" data-type="number" />
          <xsl:variable name="myid" select="../docdate" />
       <xsl:element name="a">
          <xsl:attribute name="style">font-weight: bold</xsl:attribute> 
          <xsl:attribute name="href">javascript:toggleDiv('<xsl:value-of select="$myid" />')/xsl:attribute>
          <xsl:element name="h4"> 
          <xsl:call-template name="format-date" />
       </xsl:element>
   </xsl:element>
 
   <xsl:element name="div">
      <xsl:attribute name="id"><xsl:value-of select="$myid" /></xsl:attribute>
      <xsl:attribute name="style">display:none; margin-bottom: 10px</xsl:attribute>
      <xsl:element name="table">
      <xsl:for-each select="key('sortdate', ../docdate)"> 
         <xsl:if test="position() mod 2 = 1">
            <xsl:element name="tr">
                <xsl:attribute name="style">background-color: #fff; border: 0</xsl:attribute>
                <xsl:element name="td">
                   <xsl:attribute name="style">padding: 3px</xsl:attribute>
                   <xsl:element name="a">
                       <xsl:attribute name="href"><xsl:value-of select="xref" /></xsl:attribute>
                       <xsl:value-of select="title" />
                   </xsl:element>
                  <xsl:if test="docsize/mb != ''">
                      <xsl:element name="small">
                         <xsl:value-of select="docsize/mb" />.<xsl:value-of select="docsize/kb" />Mb
                      </xsl:element>
                  </xsl:if>
                  <xsl:call-template name="otrfmt" />
                  <xsl:if test="comment != ''">
                     <xsl:element name="br" />
                     <xsl:element name="small"> 
                        <xsl:value-of select="comment" />
                     </xsl:element>
                  </xsl:if>
               </xsl:element> 
            </xsl:element>
         </xsl:if>
         <xsl:if test="position() mod 2 = 0">
            <xsl:element name="tr">
               <xsl:attribute name="style">background-color: #ede5df; border: 0</xsl:attribute>
               <xsl:element name="td">
                  <xsl:attribute name="style">padding: 3px</xsl:attribute>
                  <xsl:element name="a">
                     <xsl:attribute name="href"><xsl:value-of select="xref" /></xsl:attribute>
                     <xsl:value-of select="title" />
                  </xsl:element>
                  <xsl:if test="docsize/mb != ''">
                      <xsl:element name="small">
                         <xsl:value-of select="docsize/mb" />.<xsl:value-of select="docsize/kb" />Mb
                      </xsl:element>
                  </xsl:if>
                  <xsl:call-template name="otrfmt" />
                  <xsl:if test="comment != ''">
                     <xsl:element name="br" />
                     <xsl:element name="small"> 
                        <xsl:value-of select="comment" />
                     </xsl:element>
                  </xsl:if>
               </xsl:element> 
            </xsl:element>
         </xsl:if> 
      </xsl:for-each>
   </xsl:element>
</xsl:element>
</xsl:for-each> 
</xsl:if> 
 
<xsl:if test="//downloads/item[@category='annrept']/program[@id=$project]">
<xsl:element name="h3">
<xsl:attribute name="class">sidebar</xsl:attribute> 
Annual Reports
</xsl:element>
<xsl:element name="table">
<xsl:attribute name="style">margin: -8px 0 10px 0; padding: 0; border: 0; font: 500 'Trebuchet MS', helvetica, sans-serif; width:98%</xsl:attribute>
<xsl:for-each select="//downloads/item[@category='annrept']/program[@id=$project]">
<xsl:call-template name="populate" />
</xsl:for-each> 
</xsl:element>
</xsl:if> 
<xsl:if test="//downloads/item[@category='reports']/program[@id=$project]">
<xsl:element name="h3">
<xsl:attribute name="class">sidebar</xsl:attribute> 
Reports
</xsl:element>
<xsl:element name="table">
<xsl:attribute name="style">margin: -8px 0 10px 0; padding: 0; border: 0; font: 500 'Trebuchet MS', helvetica, sans-serif; width:98%</xsl:attribute>
<xsl:for-each select="//downloads/item[@category='reports']/program[@id=$project]">
<xsl:call-template name="populate" />
</xsl:for-each> 
</xsl:element>
</xsl:if> 
 
<xsl:if test="//downloads/item[@category='news']/program[@id=$project]">
<xsl:element name="h3">
<xsl:attribute name="class">sidebar</xsl:attribute> 
Newsletters
</xsl:element>
<xsl:element name="table">
<xsl:attribute name="style">margin: -8px 0 10px 0; padding: 0; border: 0; font: 500 'Trebuchet MS', helvetica, sans-serif; width:98%</xsl:attribute>
<xsl:for-each select="//downloads/item[@category='news']/program[@id=$project]">
<xsl:call-template name="populate" />
</xsl:for-each> 
</xsl:element>
</xsl:if> 
<xsl:if test="//downloads/item[@category='presentations']/program[@id=$project]">
<xsl:element name="h3">
<xsl:attribute name="class">sidebar</xsl:attribute> 
Presentations
</xsl:element>
<xsl:element name="table">
<xsl:attribute name="style">margin: -8px 0 10px 0; padding: 0; border: 0; font: 500 'Trebuchet MS', helvetica, sans-serif; width:98%</xsl:attribute>
<xsl:for-each select="//downloads/item[@category='presentations']/program[@id=$project]">
<xsl:call-template name="populate" />
</xsl:for-each> 
</xsl:element>
</xsl:if> 
 
<xsl:if test="//downloads/item[@category='maps']/program[@id=$project]">
<xsl:element name="h3">
<xsl:attribute name="class">sidebar</xsl:attribute> 
Maps
</xsl:element>
<xsl:element name="table">
<xsl:attribute name="style">margin: -8px 0 10px 0; padding: 0; border: 0; font: 500 'Trebuchet MS', helvetica, sans-serif; width:98%</xsl:attribute>
<xsl:for-each select="//downloads/item[@category='maps']/program[@id=$project]">
<xsl:call-template name="populate" /> 
</xsl:for-each> 
</xsl:element>
</xsl:if> 
<xsl:if test="//downloads/item[@category='success']/program[@id=$project]">
<xsl:element name="h3">
<xsl:attribute name="class">sidebar</xsl:attribute> 
Success Stories
</xsl:element>
<xsl:element name="table">
<xsl:attribute name="style">margin: -8px 0 10px 0; padding: 0; border: 0; font: 500 'Trebuchet MS', helvetica, sans-serif; width:98%</xsl:attribute>
<xsl:for-each select="//downloads/item[@category='success']/program[@id=$project]">
<xsl:call-template name="populate" /> 
</xsl:for-each> 
</xsl:element>
</xsl:if> 
<xsl:if test="//downloads/item[@category='press']/program[@id=$project]">
<xsl:element name="h3">
<xsl:attribute name="class">sidebar</xsl:attribute> 
Press Releases
</xsl:element>
<xsl:element name="table">
<xsl:attribute name="style">margin: -8px 0 10px 0; padding: 0; border: 0; font: 500 'Trebuchet MS', helvetica, sans-serif; width:98%</xsl:attribute>
<xsl:for-each select="//downloads/item[@category='press']/program[@id=$project]">
<xsl:call-template name="populate" /> 
</xsl:for-each> 
</xsl:element>
</xsl:if>
<xsl:element name="div">
<xsl:attribute name="class">hrbrk</xsl:attribute> 
</xsl:element>
</xsl:if>
 
</xsl:template>
 
<xsl:template name="populate">
<xsl:if test="position() mod 2 = 1">
<xsl:element name="tr">
<xsl:attribute name="style">background-color: #fff; border: 0</xsl:attribute>
<xsl:element name="td">
<xsl:element name="a">
<xsl:attribute name="href"><xsl:value-of select="../xref" /></xsl:attribute>
<xsl:value-of select="../title" />
</xsl:element>
<xsl:if test="../docsize/mb != ''">
 <xsl:element name="small">
<xsl:value-of select="../docsize/mb" />.<xsl:value-of select="../docsize/kb" />Mb
</xsl:element>
</xsl:if>
<xsl:call-template name="filetype" />
<xsl:if test="../comment != ''">
<xsl:element name="br" />
<xsl:element name="small"> 
<xsl:value-of select="../comment" />
</xsl:element>
</xsl:if>
</xsl:element> 
</xsl:element>
</xsl:if>
<xsl:if test="position() mod 2 = 0">
<xsl:element name="tr">
<xsl:attribute name="style">background-color: #ede5df; border: 0</xsl:attribute>
<xsl:element name="td">
<xsl:element name="a">
<xsl:attribute name="href"><xsl:value-of select="../xref" /></xsl:attribute>
<xsl:value-of select="../title" />
</xsl:element>
<xsl:if test="../docsize/mb != ''">
 <xsl:element name="small">
<xsl:value-of select="../docsize/mb" />.<xsl:value-of select="../docsize/kb" />Mb
</xsl:element>
</xsl:if>
<xsl:call-template name="filetype" />
<xsl:if test="../comment != ''">
<xsl:element name="br" />
<xsl:element name="small"> 
<xsl:value-of select="../comment" />
</xsl:element>
</xsl:if>
</xsl:element> 
</xsl:element>
</xsl:if>
</xsl:template>
<xsl:template name="filetype"> 
<xsl:choose>
<xsl:when test="../docformat='PDF'">
<xsl:element name="a">
<xsl:attribute name="href">http://www.adobe.com/products/acrobat/readstep2.html</xsl:attribute>
<xsl:element name="img">
<xsl:attribute name="src">../images/pdf_ico.jpg</xsl:attribute>
<xsl:attribute name="title">Click here to download/install Adobe PDF Reader</xsl:attribute>
<xsl:attribute name="alt">Click here to download/install Adobe PDF Reader</xsl:attribute>
<xsl:attribute name="class">dwnldimg</xsl:attribute>
</xsl:element>
</xsl:element>
</xsl:when>
<xsl:when test="../docformat='DOC'">
<xsl:element name="a">
<xsl:attribute name="href">http://www.microsoft.com/downloads/details.aspx?FamilyID=3657ce88-7cfa-457a-9aec-f4f827f20cac&amp;DisplayLang=en</xsl:attribute>
<xsl:element name="img">
<xsl:attribute name="src">../images/word_ico.jpg</xsl:attribute>
<xsl:attribute name="title">Click here to download/install MS Word Reader</xsl:attribute>
<xsl:attribute name="alt">Click here to download/install MS Word Reader</xsl:attribute>
<xsl:attribute name="class">dwnldimg</xsl:attribute>
</xsl:element> 
</xsl:element>
</xsl:when>
<xsl:when test="../docformat='XLS'">
<xsl:element name="a">
<xsl:attribute name="href">http://www.microsoft.com/downloads/details.aspx?FamilyID=1cd6acf9-ce06-4e1c-8dcf-f33f669dbc3a&amp;DisplayLang=en</xsl:attribute>
<xsl:element name="img">
<xsl:attribute name="src">../images/xls_ico.jpg</xsl:attribute>
<xsl:attribute name="title">Click here to download/install MS Excel Reader</xsl:attribute>
<xsl:attribute name="alt">Click here to download/install MS Excel Reader</xsl:attribute>
<xsl:attribute name="class">dwnldimg</xsl:attribute>
</xsl:element> 
</xsl:element>
</xsl:when>
<xsl:when test="../docformat='ZIP'">
<xsl:element name="a">
<xsl:attribute name="href">http://www.winzip.com/downwz.htm</xsl:attribute>
<xsl:element name="img">
<xsl:attribute name="src">../images/zip_ico.jpg</xsl:attribute>
<xsl:attribute name="title">Click here to download/install WinZip</xsl:attribute>
<xsl:attribute name="alt">Click here to download/install WinZip</xsl:attribute>
<xsl:attribute name="class">dwnldimg</xsl:attribute>
</xsl:element> 
</xsl:element>
</xsl:when>
<xsl:when test="../docformat='PPT'">
<xsl:element name="a">
<xsl:attribute name="href">http://www.microsoft.com/downloads/details.aspx?FamilyID=048dc840-14e1-467d-8dca-19d2a8fd7485&amp;DisplayLang=en</xsl:attribute>
<xsl:element name="img">
<xsl:attribute name="src">../images/ppt_ico.jpg</xsl:attribute>
<xsl:attribute name="title">Click here to install MS Powerpoint Reader</xsl:attribute>
<xsl:attribute name="alt">Click here to install MS Powerpoint Reader</xsl:attribute>
<xsl:attribute name="class">dwnldimg</xsl:attribute>
</xsl:element> 
</xsl:element>
</xsl:when>
<xsl:when test="../docformat='JPG'">
<xsl:element name="img">
<xsl:attribute name="src">../images/jpg_ico.jpg</xsl:attribute>
<xsl:attribute name="title">This is a JPG image file. You may view this in your web browser or through a program such as MS Paint, Adobe Photoshop, or iPhoto.</xsl:attribute>
<xsl:attribute name="alt">This is a JPG image file. You may view this in your web browser or through a program such as MS Paint, Adobe Photoshop, or iPhoto.</xsl:attribute>
<xsl:attribute name="class">dwnldimg</xsl:attribute>
</xsl:element>
</xsl:when>
<xsl:when test="../docformat='MPG'">
<xsl:element name="img">
<xsl:attribute name="src">../images/mpg_ico.jpg</xsl:attribute>
<xsl:attribute name="title">This is a MPEG/MPG multimedia file. You may view this with Windows Media Player, Quicktime, or WinAmp.</xsl:attribute> 
<xsl:attribute name="alt">This is a MPEG/MPG multimedia file. You may view this with Windows Media Player, Quicktime, or WinAmp.</xsl:attribute> 
<xsl:attribute name="class">dwnldimg</xsl:attribute>
</xsl:element>
</xsl:when>
<xsl:when test="../docformat='WMV'">
<xsl:element name="img">
<xsl:attribute name="src">../images/wmv_ico.jpg</xsl:attribute>
<xsl:attribute name="title">This is a WMV multimedia file. You may view this with Windows Media Player, Quicktime, or WinAmp.</xsl:attribute> 
<xsl:attribute name="alt">This is a WMV multimedia file. You may view this with Windows Media Player, Quicktime, or WinAmp.</xsl:attribute> 
<xsl:attribute name="class">dwnldimg</xsl:attribute>
</xsl:element>
</xsl:when>
<xsl:when test="../docformat='TXT'">
<xsl:element name="img">
<xsl:attribute name="src">../images/txt2_ico.jpg</xsl:attribute>
<xsl:attribute name="title">This is a Plain Text Format file. You may view this in Notepad, Wordpad, MS Word, WordPerfect, or Mac Pages.</xsl:attribute> 
<xsl:attribute name="alt">This is a Plain Text Format file. You may view this in Notepad, Wordpad, MS Word, WordPerfect, or Mac Pages.</xsl:attribute> 
<xsl:attribute name="class">dwnldimg</xsl:attribute>
</xsl:element>
</xsl:when>
<xsl:when test="../docformat='RTF'">
<xsl:element name="img">
<xsl:attribute name="src">../images/txt_ico.jpg</xsl:attribute>
<xsl:attribute name="title">This is a Rich Text Format file. You may view this in Notepad, Wordpad, MS Word, WordPerfect, or Mac Pages.</xsl:attribute> 
<xsl:attribute name="alt">This is a Rich Text Format file. You may view this in Notepad, Wordpad, MS Word, WordPerfect, or Mac Pages.</xsl:attribute> 
<xsl:attribute name="class">dwnldimg</xsl:attribute>
</xsl:element>
</xsl:when>
<xsl:when test="../docformat='MDB'">
<xsl:element name="a">
<xsl:attribute name="href">http://support.microsoft.com/kb/175274</xsl:attribute>
<xsl:element name="img">
<xsl:attribute name="src">../images/mdb_ico.jpg</xsl:attribute>
<xsl:attribute name="title">Click here to download/install MS Snapshot Viewer for MS Access</xsl:attribute> 
<xsl:attribute name="alt">Click here to download/install MS Snapshot Viewer for MS Access</xsl:attribute> 
<xsl:attribute name="class">dwnldimg</xsl:attribute>
</xsl:element>
</xsl:element>
</xsl:when> 
<xsl:otherwise>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
 
<xsl:template name="format-date">
<xsl:variable name="d"><xsl:value-of select="../docdate" /></xsl:variable>
<xsl:call-template name="long_date"><xsl:with-param name="date" select="$d" /></xsl:call-template>
</xsl:template>
<xsl:template name="long_date">
<xsl:param name="date" />
<xsl:value-of select="substring($date, 7, 2)" /> 
<xsl:variable name="month" select="substring($date, 5, 2)" />
<xsl:choose>
<xsl:when test="$month=01">January</xsl:when>
<xsl:when test="$month=02">February</xsl:when>
<xsl:when test="$month=03">March</xsl:when>
<xsl:when test="$month=04">April</xsl:when>
<xsl:when test="$month=05">May</xsl:when>
<xsl:when test="$month=06">June</xsl:when>
<xsl:when test="$month=07">July</xsl:when>
<xsl:when test="$month=08">August</xsl:when>
<xsl:when test="$month=09">September</xsl:when>
<xsl:when test="$month=10">October</xsl:when>
<xsl:when test="$month=11">November</xsl:when>
<xsl:when test="$month=12">December</xsl:when>
<xsl:otherwise>INVALID MONTH</xsl:otherwise>
</xsl:choose> 
<xsl:value-of select="substring($date, 1, 4)" />
</xsl:template>
 
<xsl:template name="otrfmt"> 
<xsl:choose>
<xsl:when test="docformat='PDF'">
<xsl:element name="a">
<xsl:attribute name="href">http://www.adobe.com/products/acrobat/readstep2.html</xsl:attribute>
<xsl:element name="img">
<xsl:attribute name="src">../images/pdf_ico.jpg</xsl:attribute>
<xsl:attribute name="title">Click here to download/install Adobe PDF Reader</xsl:attribute>
<xsl:attribute name="alt">Click here to download/install Adobe PDF Reader</xsl:attribute>
<xsl:attribute name="class">dwnldimg</xsl:attribute>
</xsl:element>
</xsl:element>
</xsl:when>
<xsl:when test="docformat='DOC'">
<xsl:element name="a">
<xsl:attribute name="href">http://www.microsoft.com/downloads/details.aspx?FamilyID=3657ce88-7cfa-457a-9aec-f4f827f20cac&amp;DisplayLang=en</xsl:attribute>
<xsl:element name="img">
<xsl:attribute name="src">../images/word_ico.jpg</xsl:attribute>
<xsl:attribute name="title">Click here to download/install MS Word Reader</xsl:attribute>
<xsl:attribute name="alt">Click here to download/install MS Word Reader</xsl:attribute>
<xsl:attribute name="class">dwnldimg</xsl:attribute>
</xsl:element> 
</xsl:element>
</xsl:when>
<xsl:when test="docformat='XLS'">
<xsl:element name="a">
<xsl:attribute name="href">http://www.microsoft.com/downloads/details.aspx?FamilyID=1cd6acf9-ce06-4e1c-8dcf-f33f669dbc3a&amp;DisplayLang=en</xsl:attribute>
<xsl:element name="img">
<xsl:attribute name="src">../images/xls_ico.jpg</xsl:attribute>
<xsl:attribute name="title">Click here to download/install MS Excel Reader</xsl:attribute>
<xsl:attribute name="alt">Click here to download/install MS Excel Reader</xsl:attribute>
<xsl:attribute name="class">dwnldimg</xsl:attribute>
</xsl:element> 
</xsl:element>
</xsl:when>
<xsl:when test="docformat='ZIP'">
<xsl:element name="a">
<xsl:attribute name="href">http://www.winzip.com/downwz.htm</xsl:attribute>
<xsl:element name="img">
<xsl:attribute name="src">../images/zip_ico.jpg</xsl:attribute>
<xsl:attribute name="title">Click here to download/install WinZip</xsl:attribute>
<xsl:attribute name="alt">Click here to download/install WinZip</xsl:attribute>
<xsl:attribute name="class">dwnldimg</xsl:attribute>
</xsl:element> 
</xsl:element>
</xsl:when>
<xsl:when test="docformat='PPT'">
<xsl:element name="a">
<xsl:attribute name="href">http://www.microsoft.com/downloads/details.aspx?FamilyID=048dc840-14e1-467d-8dca-19d2a8fd7485&amp;DisplayLang=en</xsl:attribute>
<xsl:element name="img">
<xsl:attribute name="src">../images/ppt_ico.jpg</xsl:attribute>
<xsl:attribute name="title">Click here to install MS Powerpoint Reader</xsl:attribute>
<xsl:attribute name="alt">Click here to install MS Powerpoint Reader</xsl:attribute>
<xsl:attribute name="class">dwnldimg</xsl:attribute>
</xsl:element> 
</xsl:element>
</xsl:when>
<xsl:when test="docformat='JPG'">
<xsl:element name="img">
<xsl:attribute name="src">../images/jpg_ico.jpg</xsl:attribute>
<xsl:attribute name="title">This is a JPG image file. You may view this in your web browser or through a program such as MS Paint, Adobe Photoshop, or iPhoto.</xsl:attribute>
<xsl:attribute name="alt">This is a JPG image file. You may view this in your web browser or through a program such as MS Paint, Adobe Photoshop, or iPhoto.</xsl:attribute>
<xsl:attribute name="class">dwnldimg</xsl:attribute>
</xsl:element>
</xsl:when>
<xsl:when test="docformat='MPG'">
<xsl:element name="img">
<xsl:attribute name="src">../images/mpg_ico.jpg</xsl:attribute>
<xsl:attribute name="title">This is a MPEG/MPG multimedia file. You may view this with Windows Media Player, Quicktime, or WinAmp.</xsl:attribute> 
<xsl:attribute name="alt">This is a MPEG/MPG multimedia file. You may view this with Windows Media Player, Quicktime, or WinAmp.</xsl:attribute> 
<xsl:attribute name="class">dwnldimg</xsl:attribute>
</xsl:element>
</xsl:when>
<xsl:when test="docformat='WMV'">
<xsl:element name="img">
<xsl:attribute name="src">../images/wmv_ico.jpg</xsl:attribute>
<xsl:attribute name="title">This is a WMV multimedia file. You may view this with Windows Media Player, Quicktime, or WinAmp.</xsl:attribute> 
<xsl:attribute name="alt">This is a WMV multimedia file. You may view this with Windows Media Player, Quicktime, or WinAmp.</xsl:attribute> 
<xsl:attribute name="class">dwnldimg</xsl:attribute>
</xsl:element>
</xsl:when>
<xsl:when test="docformat='TXT'">
<xsl:element name="img">
<xsl:attribute name="src">../images/txt2_ico.jpg</xsl:attribute>
<xsl:attribute name="title">This is a Plain Text Format file. You may view this in Notepad, Wordpad, MS Word, WordPerfect, or Mac Pages.</xsl:attribute> 
<xsl:attribute name="alt">This is a Plain Text Format file. You may view this in Notepad, Wordpad, MS Word, WordPerfect, or Mac Pages.</xsl:attribute> 
<xsl:attribute name="class">dwnldimg</xsl:attribute>
</xsl:element>
</xsl:when>
<xsl:when test="docformat='RTF'">
<xsl:element name="img">
<xsl:attribute name="src">../images/txt_ico.jpg</xsl:attribute>
<xsl:attribute name="title">This is a Rich Text Format file. You may view this in Notepad, Wordpad, MS Word, WordPerfect, or Mac Pages.</xsl:attribute> 
<xsl:attribute name="alt">This is a Rich Text Format file. You may view this in Notepad, Wordpad, MS Word, WordPerfect, or Mac Pages.</xsl:attribute> 
<xsl:attribute name="class">dwnldimg</xsl:attribute>
</xsl:element>
</xsl:when>
<xsl:when test="docformat='MDB'">
<xsl:element name="a">
<xsl:attribute name="href">http://support.microsoft.com/kb/175274</xsl:attribute>
<xsl:element name="img">
<xsl:attribute name="src">../images/mdb_ico.jpg</xsl:attribute>
<xsl:attribute name="title">Click here to download/install MS Snapshot Viewer for MS Access</xsl:attribute> 
<xsl:attribute name="alt">Click here to download/install MS Snapshot Viewer for MS Access</xsl:attribute> 
<xsl:attribute name="class">dwnldimg</xsl:attribute>
</xsl:element>
</xsl:element>
</xsl:when> 
<xsl:otherwise>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
Then finally is the javascript, so that you have the WHOLE picture:

Code:
 
function transformXML(xmlDocURL, xslDocURL, divID, proj1)
{
// declare the local variables
var xmlDoc, xslDoc, docProcessor, docCache, DocRequest, docFragment;
var proj = proj1;
// try the following
try
{
// instantiate and load the xml document
xmlDoc = new ActiveXObject("MSXML2.DOMDocument");
xmlDoc.async = false;
xmlDoc.load(xmlDocURL);
// instantiate and load the xsl document
xslDoc = new ActiveXObject("MSXML2.FreeThreadedDOMDocument");
xslDoc.async = false;
xslDoc.load(xslDocURL);
// prepare the xsl document for transformation
docCache = new ActiveXObject("MSXML2.XSLTemplate");
docCache.stylesheet = xslDoc;
// get date and set date variables
var today = new Date();
var theDay = today.getUTCDate();
var theMonth = today.getMonth() + 1;
var theYear = today.getFullYear()+"";
if (theDay.toString().length==1)
{
theDay = "0" + theDay;
}
if (theMonth.toString().length==1)
{
theMonth = "0" + theMonth;
}
 
var myDate = theYear + theMonth + theDay;
var dow = today.getDay();
// instantiate the document processor and submit the xml document
docProcessor = docCache.createProcessor();
docProcessor.input = xmlDoc;
// add parameters to the xsl document
docProcessor.addParameter("project", proj, "");
docProcessor.addParameter("today", myDate, "");
docProcessor.addParameter("day", dow, "");
// process the documents into html and submit to the passed div box
docProcessor.transform();
// divID.innerHTML = docProcessor.output;
document.getElementById(divID).innerHTML = docProcessor.output;
}
// catch any errors from the above code
catch(e)
{
// try the following
try
{
// instantiate and load the xml document
docRequest = new XMLHttpRequest();
docRequest.open("GET", xmlDocURL, false);
docRequest.send(null);
xmlDoc = docRequest.responseXML;
// instantiate and load the xsl document
docRequest = new XMLHttpRequest();
docRequest.open("GET", xslDocURL, false);
docRequest.send(null);
xslDoc = docRequest.responseXML;
// get date and set date variables
var today = new Date();
var theDay = today.getUTCDate();
var theMonth = today.getMonth() + 1;
var theYear = today.getFullYear()+"";
if (theDay.toString().length==1)
{
theDay = "0" + theDay;
}
if (theMonth.toString().length==1)
{
theMonth = "0" + theMonth;
}
 
var myDate = theYear + theMonth + theDay;
var dow = today.getDay();
// instantiate the document processor and submit the xsl document
docProcessor = new XSLTProcessor();
docProcessor.importStylesheet(xslDoc);
// add parameters to the xsl document
docProcessor.setParameter(null, "project", proj);
docProcessor.setParameter(null, "today", myDate);
docProcessor.setParameter(null, "day", dow);
// clear the passed div if anything was in it
document.getElementById(divID).innerHTML = "";
// process the documents into html and submit to the passed div
docFragment = docProcessor.transformToFragment(xmlDoc, document);
document.getElementById(divID).appendChild(docFragment);
}
// catch any errors from the above code
catch(e)
{
// do nothing
}
}
}

Last edited by athos; April 28th, 2009 at 10:51 AM..
 
Old April 29th, 2009, 12:40 AM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 291
Thanks: 9
Thanked 29 Times in 29 Posts
Thumbs up

Try with the changes below:

1. I changed the lines like
Code:
<xsl:when test="$month=01">January</xsl:when>
to ( i have inserted single quote character before 01 below)
Code:
<xsl:when test="$month='01'">January</xsl:when>


2. Then I changed the line
Code:
<xsl:attribute name="href">javascript:toggleDiv('<xsl:value-of select="$myid"/>')/xsl:attribute>
to (closing tag was incomplete)
Code:
<xsl:attribute name="href">javascript:toggleDiv('<xsl:value-of select="$myid"/>')</xsl:attribute>
I don't know whether the above are typo errors. But after these changes, correct values are obtained for any date value inside <docdate>.
__________________
Rummy

Last edited by mrame; April 29th, 2009 at 12:46 AM..
The Following User Says Thank You to mrame For This Useful Post:
athos (April 29th, 2009)
 
Old April 29th, 2009, 04:37 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

I had to make a few changes to get your stylesheet to compile. Most of them were the same changes Martin made - also I had to change "&" to "& amp;" in a number of places, and I had to change the encoding to iso-8859-1. Some of these may have been transmission errors, but in general, you don't seem to be helping anyone by posting code that won't even compile.

When I finally got it to compile, I ran it in both IE and Firefox and I don't get the "missing record" problem.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old April 29th, 2009, 01:35 PM
Authorized User
 
Join Date: Oct 2008
Posts: 26
Thanks: 2
Thanked 0 Times in 0 Posts
Default

Thanks so very much mrame. After looking at lines of code, I'm afraid I missed those two items. I appreciate your patience and kindness.

Mhkay....I'll go track down the errant ampersands.

And....I am a noob at this, which I've posted before. This was my first project. I'm doing the best that I can despite no education, no access to training (my boss forbids it for budgetary reasons), and having to code everything in a glorified notepad. (I work two jobs to make ends meet, so classes are out of the question right now.) I miss stuff, I make errors from lack of experience. I don't have the privilege of having authored books or communicating with other experienced XSLT people like you. The only way to not be a noob is to do the best to self-educate and drink up the knowledge that others willingly provide, and I'm very thankful. However, please keep in mind that there are others on this forum like me when you respond.





Similar Threads
Thread Thread Starter Forum Replies Last Post
format-number dropping 0 stolte XSLT 1 January 18th, 2008 04:46 PM
"Are you Sure" Before Dropping List in ComboBox lam2rw Excel VBA 2 September 22nd, 2006 06:57 AM
Dropping constraints epp_b MySQL 2 September 12th, 2006 09:22 PM
bizarre problem scud-murphy Dreamweaver (all versions) 1 June 1st, 2006 03:59 PM
Update Record Issue phungleon Classic ASP Databases 5 June 10th, 2005 04:26 AM





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