This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: using xt-extensions for getting a string of date


Felix Shumacher said
> I am trying to use the extent the date.xsl example from the xt-distro.
> I want it to print the string for a given date, not the actual date
> like that demo does. I tried something like this
>
> <xsl:stylesheet
>   version="1.0"
>   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>   xmlns:date="http://www.jclark.com/xt/java/java.util.Date">
....
>       <p><xsl:value-of select="date:to-string(date:new(2000,1,2))"/></p>
...
> It should give out the strings for the 02.01.2000. But xt just tells
> me:
> new:illegal arguments

I've been working on this part of xt myself, and I sort of hope that
thinking through your issue will help me think about mine.

There are two troubles here...a bit with the Date itself, mostly with the
conversion. Clark's very brief documentation, in "xt.htm", says that
xt numbers are traded for Java Doubles, and the IllegalArgumentException
message you're getting from his ExtensionHandlerImpl.java comes from
trying to use Doubles to construct a Date. So far as I know, you can
only do this by subclassing Date like so:
-----------------------------------------------------------------
package MyNa.jspUtil; // if you want it in a package

public class DDate extends java.util.Date{
  public DDate(Double y, Double m, Double d){
    super(y.intValue(),m.intValue(),d.intValue());
  }
} 
-----------------------------------------------------------------
I then put the package in a jar (it has to be in a jar (?)) like so:
  javac MyNa/jspUtil/DDate.java
  jar -uf MyNajsp.jar MyNa/jspUtil/DDate.class
and make sure the jar is on the class path or in the right lib/ext
directory.

Then I can call it, with other examples, like so (some header
stuff not needed but I'm editting an existing example); first I
call on the straight date:new(), then on System.getProperties(),
then on DDate(100,1,1) (That's Feb 1, 2000, and as you'll see
below it shows as "Tue Feb 01 00:00:00 EST 2000"; Date is a 
deprecated class, after all, and DDate(2000,1,1) will show Feb 1, 
3900). And then, just for the fun of it, I call on a "vdoc" class 
which generates a NodeIterator as output from a jdbc ResultSet.
-----------------------------------------------------------------
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns="http://www.w3.org/TR/xhtml1/strict"
  xmlns:date="http://www.jclark.com/xt/java/java.util.Date"
  xmlns:prop="http://www.jclark.com/xt/java/java.util.Properties"
  xmlns:sys="http://www.jclark.com/xt/java/java.lang.System"
  xmlns:ddate="http://www.jclark.com/xt/java/MyNa.jspUtil.DDate"
  xmlns:vdoc="http://www.jclark.com/xt/java/MyNa.jspUtil.QueryDoc"
>
<xsl:output   method="html" indent="yes" encoding="UTF-8"
    media-type="text/html" omit-xml-declaration="no"
    doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" 
    doctype-system="http://www.w3.org/TR/xhtml1/DTD/strict.dtd"
 />

<xsl:param name="theSessionID" select="NoHttpSessionIDProvided"/>

<xsl:template match="/">
<html>
<head><title>Weather; you asked for all </title></head>
<body>
  <p><xsl:value-of select="date:to-string(date:new())"/></p>
  <p><xsl:value-of select="prop:to-string(sys:get-properties())"/></p>
  <p><xsl:value-of select="date:to-string(ddate:new(100,1,1))"/></p>

  <p><xsl:value-of select="$theSessionID"/></p>
  <p>
     <xsl:for-each select="vdoc:query-result($theSessionID)/*" >
     <p>field <xsl:value-of select="@*" /> = <xsl:value-of select="." /> </p>
     </xsl:for-each>
  </p>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
-----------------------------------------------------------------
When I call this with a top-level parameter of "theSessionID", which
actually I do from an editted XSLServlet class, i get
-----------------------------------------------------------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
     "http://www.w3.org/TR/xhtml1/DTD/strict.dtd">
<html xmlns:date="http://www.jclark.com/xt/java/java.util.Date"
xmlns:ddate="http://www.jclark.com/xt/java/MyNa.jspUtil.DDate"
xmlns:int="http://www.jclark.com/xt/java/java.lang.Integer"
xmlns:prop="http://www.jclark.com/xt/java/java.util.Properties"
xmlns:sys="http://www.jclark.com/xt/java/java.lang.System"
xmlns:vdoc="http://www.jclark.com/xt/java/MyNa.jspUtil.QueryDoc" 
xmlns="http://www.w3.org/TR/xhtml1/strict">
<head>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Weather; you asked for all </title>
</head>
<body>
<p>Wed Mar 08 09:22:05 EST 2000</p>
<p>{java.specification.name=Java Platform API Specification, 
  awt.toolkit=sun.awt.windows.WToolkit, java.version=1.2.2, 
  java.awt.graphicsenv=sun.awt.Win32GraphicsEnvironment, 
  user.timezone=America/New_York, ......blah,blah.........
  java.class.path=.\classes;.\webserver.jar;...blah.......
    C:\jswdk-1.0\examples\WEB-INF\jsp\beans\MyNajsp.jar;....}
</p>

<p>Tue Feb 01 00:00:00 EST 2000</p>

<p>To1010mC3484519333900402At</p>
<p>
<p>field Zip = 12345</p>
<p>field Day = yesterday</p>
<p>field RecTime = 3/5/2000 3:04:54 PM</p>
<p>field Temp = 35</p>
<p>field DayLo = 20</p>
<p>field DayHi = 50</p>
<p>field Precip = 15</p>
<p>field Warn = no warn</p>
<p>field Tomorrow = no tomorrow</p>
<p>field NextDay = no nextday</p>
</p>
</body>
</html>
-----------------------------------------------------------------

The mechanism is very nice...as I was moaning yesterday, I can't
get it to generate non-html output and still set the contentType
so I can't see it on my simulated WAP phone, but the basic
mechanism is very nice.

Tom Myers


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]