RE: Using xquery-operators in XSLT's

"Michael Kay" <[email protected]>
Newsgroups gmane.comp.java.jdom.general
Message-ID <012201c7b361$53bc08a0$6701a8c0@turtle>
XSLT 2.0 provides the same set of functions and operators as XQuery 1.0.
 
The default XSLT processor with JDOM only implements XSLT 1.0. However, you
can also use Saxon with JDOM, and Saxon implements XSLT 2.0. (Saxon also
implements XQuery, so you can use that if you prefer).
 
However, you have (like many people) misunderstood the nature of the
functions in the op: namespace. These exist purely for specification
reasons, they are not exposed directly to users. Instead, the functions
underpin operators, in this case the subtraction operator "-" when applied
to two values of type xs:dateTime respectively. 
 
Another point: you are trying to apply the function to values of the wrong
type. You need to do something like:
 
xs:dateTime(sgp4:SGP4Set/sgp4:startDateTime) -
xs:dateTime(sgp4:SGP4Set/sgp4:endDateTime)
 
Michael Kay
http://www.saxonica.com/


  _____  

From: [email protected] [mailto:[email protected]]
On Behalf Of Holmes, Charles V.
Sent: 20 June 2007 14:42
To: [email protected]
Subject: [jdom-interest] Using xquery-operators in XSLT's


Given a startTime (dateTime), endTime (dateTime) and intervals (integer),
I'm attempting to come up with dateTimes evenly spaced between the startTime
and endTime.  It seems that I need to use xquery-operators to do this since
XSLT doesn't seem to provide the kind of date manipulation I need.  When I
try to run this, I get an error (also below). 
 
Am I going about this the correct way, or is there a better way to do this?
Does JDOM provide support for xquery-operators in XSLT?  If not, is there
another way to get these time intervals?  Or should I be using another
processor for this?  On a slightly related node, position() works, but
fn:position() doesn't.  Is this a XSLT 1.0 vs 2.0 thing?
 
Thanks,
Charles
 
<-------------ERROR---------------->
 
ERROR:  'The first argument to the non-static Java function
'subtractDateTimes' is not a valid object reference.'
FATAL ERROR:  'Could not compile stylesheet'
org.jdom.transform.XSLTransformException: Could not construct
XSLTransformer: Could not compile stylesheet
 
 
<--------------------STYLESHEET---------------------------->
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:sgp4="http://sever/common/sgp4"
 xmlns:fn="http://www.w3.org/2005/02/xpath-functions"
 xmlns:op="http://www.w3.org/2001/12/xquery-operators"
 xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xsl:output method="xml" />
 
<xsl:variable name="startTime" select="sgp4:SGP4Set/sgp4:startDateTime" />
<xsl:variable name="endTime"   select="sgp4:SGP4Set/sgp4:stopDateTime" />
<xsl:variable name="steps"     select="sgp4:SGP4Set/sgp4:steps" />
 
<xsl:template match="/">
 <result>
  <xsl:apply-templates />
 </result>
</xsl:template>
 
<xsl:template match="sgp4:timeSeries">
 <xsl:apply-templates/>
</xsl:template>
 
<xsl:template match="sgp4:SGP4Set/sgp4:timeSeries/sgp4:latLonXYZ">
 <timeLocation>
  <xsl:value-of select="$startTime + (position() *
(op:subtract-dateTimes($startTime, $endTime) div steps))"/>
 </timeLocation>
</xsl:template>
 
</xsl:stylesheet>
<------------------------------CODE-------------------------------->
I'm then trying to transform it with the following code:
  String str = "<SGP4Set>" + 
  "<startDateTime>2007-06-14T15:21:10.666+00:00</startDateTime>" + 
  "<stopDateTime>2007-06-15T15:21:10.666+00:00</stopDateTime>" + 
  "<steps>3</steps>" + 
  "<elsetLine1>1 25544U 98067A   07164.33827071 -.00073317  00000-0 -41936-3
0  3835</elsetLine1>" + 
  "<elsetLine2>2 25544 051.6334 123.8003 0008065 317.7457 198.0340
15.78097880490162</elsetLine2>" + 
  "<timeSeries>" + 
    "<latLonXYZ lat=\"-4.464837391096287\" lon=\"340.6854284795686\"
height=\"333.1668901789984\" x=\"-2673.3476456175044\"
y=\"6133.803881468676\" z=\"-519.1427930784305\"
time=\"1874.1666666665114\"/>" + 
    "<latLonXYZ lat=\"4.510324008580091\" lon=\"347.0371991370784\"
height=\"332.65914429961356\" x=\"-3407.888183523746\"
y=\"5757.110331891201\" z=\"524.3810905059737\"
time=\"1877.0466666665116\"/>" + 
    "<latLonXYZ lat=\"13.413484560305426\" lon=\"353.56508317710467\"
height=\"333.1856535368585\" x=\"-4008.464009082425\"
y=\"5154.103666587921\" z=\"1547.231195854609\"
time=\"1879.9266666665117\"/>" + 
  "</timeSeries>" +
"</SGP4Set>";
 
   // setup our transformer 
   SAXBuilder builder = new SAXBuilder();
   XSLTransformer transformer = new XSLTransformer("SGP4ToKML.xslt");
 
   // setup our document to transform
   StringReader sr = new StringReader(str);
   Document doc = builder.build(sr);
   
   // save the transformed document in doc2
   Document doc2 = transformer.transform(doc);

   String result = new XMLOutputter().outputString(doc);
   
   result = new XMLOutputter().outputString(doc2);
   
   XmlObject obj = XmlObject.Factory.parse(result);
   System.out.println(obj);

_______________________________________________
To control your jdom-interest membership:
http://www.jdom.org/mailman/options/jdom-interest/[email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.