views:

320

answers:

2

Hello guys,

I'm using date:format-date template EXSLT file I'm using XSLT 1.0 and MSXML3.0 as the processor.

My date:format-date template EXSLT file's declaration is:

<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:msxsl="urn:schemas-microsoft-com:xslt"
  xmlns:date="http://exslt.org/dates-and-times"
  xmlns:str="http://exslt.org/strings"
  extension-element-prefixes="msxsl date str">
   ...
</xsl:stylesheet>

I cannot use document() function due to the 3rd party restrictions. So I have changed the months and days (similarly) from XML snippet:

<date:months>
  <date:month length="31" abbr="Jan">January</date:month>
  <date:month length="28" abbr="Feb">February</date:month>
  <date:month length="31" abbr="Mar">March</date:month>
  <date:month length="30" abbr="Apr">April</date:month>
  <date:month length="31" abbr="May">May</date:month>
  <date:month length="30" abbr="Jun">June</date:month>
  <date:month length="31" abbr="Jul">July</date:month>
  <date:month length="31" abbr="Aug">August</date:month>
  <date:month length="30" abbr="Sep">September</date:month>
  <date:month length="31" abbr="Oct">October</date:month>
  <date:month length="30" abbr="Nov">November</date:month>
  <date:month length="31" abbr="Dec">December</date:month>
</date:months>

to the variable:

 <xsl:variable name="months">
   <month length="31" abbr="Jan">January</month>
   <month length="28" abbr="Feb">February</month>
   <month length="31" abbr="Mar">March</month>
   <month length="30" abbr="Apr">April</month>
   <month length="31" abbr="May">May</month>
   <month length="30" abbr="Jun">June</month>
   <month length="31" abbr="Jul">July</month>
   <month length="31" abbr="Aug">August</month>
   <month length="30" abbr="Sep">September</month>
   <month length="31" abbr="Oct">October</month>
   <month length="30" abbr="Nov">November</month>
   <month length="31" abbr="Dec">December</month>
</xsl:variable>

And correspondingly, I've changed the code that originally uses document() function from:
[from month processing bit of EXSLT stylesheet]

<xsl:variable name="month-node" select="document('')/*/date:months/date:month[number($month)]" />

to use MSXML3.0 node-set function:

<xsl:variable name="month-node" select="msxsl:node-set($months)/month[number($month)]" />

So I assumed that this would work.

According to the EXLT instructions "The format pattern string is interpreted as described for the JDK 1.1 SimpleDateFormat class." [I used current version].

I'm specifing the month in accordance to SimpleDateFormat class as 'dd MMMMM yyyy' so that the month will be the full month's name, for example January. But it doesn't work :( I've looked in EXSLT stylesheet and it has got the logic to do that. Also there is logic to display the name of the week for a day using 'E' pattern, which doesn't work for me. Maybe changing from using document() to variables broke it.

Would really appreciate any help.

Many thanks!

EXAMPLES

<xsl:call-template name="date:format-date">
    <xsl:with-param name="date-time" select="'2010-07-01'"/>
    <xsl:with-param name="pattern" select="'dd MMMMM yyyy'" />
</xsl:call-template>

As I understand from SimpleDateFormat class docs this should result in 01 July 2010 and what I get is 01 07 2010



<xsl:call-template name="date:format-date">
    <xsl:with-param name="date-time" select="'2010-07-01'"/>
    <xsl:with-param name="pattern" select="'EEE, dd MMMMM yyyy'" />
</xsl:call-template>

This should result in Mon, 01 July 2010 and what I get is , 01 07 2010

A: 

When you use msxml:node-set on a rootless fragment of XML (like your list of months), the function automatically creates a root to contain the fragment.

So in your case your path from the node set is wrong:

msxsl:node-set($months)/month[number($month)]

This is wrong because /month is not the root of $months. You can fix it easily by skipping the artificial root and going to month directly:

msxsl:node-set($months)//month[number($month)]

Note the // operator instead of the / operator.

EDIT

Upon testing I see that I'm wrong. In fact, the original snippet that you are using works fine for me. The // operator is unnecessary. Are you sure your $month variable is being set correctly?

Welbog
@Welbog: I think it is. I've edited the structure of $months so that I can use it without document(). I do get results, but not exactly formated in the correct way. I've added examples in the question.
DashaLuna
A: 

According to the EXSLT page you reference (date:format-date template EXSLT file):

There are currently no XSLT processors that we know of that support date:format-date natively.

What implementation are you using? It doesn't seem to be supported natively in MSXML.

Adam J.R. Erickson