[jdom-interest] Using xquery-operators in XSLT's

Holmes, Charles V. cholmes at mitre.org
Wed Jun 20 06:42:02 PDT 2007


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);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.jdom.org/pipermail/jdom-interest/attachments/20070620/46ec40b2/attachment.htm


More information about the jdom-interest mailing list