[jdom-interest] receiving java.util.EmptyStackException

Alan Eustace alan.eustace at dit.ie
Mon Apr 15 03:57:11 PDT 2002


Hello all,
I'm getting the exception below when I try to transform an XML/XSL 
combination to VRML using JDOM-8.

I use the XSLTransform example provided in jdom/samples. When I use the 
provided catalog.xsl/xml files it works fine, but when I use my own xml/xsl 
files it throws an exception thus:
Using Xalan on its own (see code below)  I can achieve the transformation 
fine, which leads me to believe  this is a JDOM issue. Has anyone come 
across this before?
(I found a similar posting on the mulberry xsl list: 
http://www.biglist.com/lists/xsl-list/archives/200201/msg00714.html)

Thanks for any help

Best regards,

Alan Eustace.

*********************************
exception:
*********************************
org.jdom.JDOMException: XSLT Transformation failed: 
java.util.EmptyStackException
         at XSLTransform.transform(XSLTransform.java:32)
         at XSLTransform.main(XSLTransform.java:15)
Root cause: javax.xml.transform.TransformerException: 
java.util.EmptyStackException
         at 
org.apache.xalan.transformer.TransformerImpl.transformNode(TransformerImpl.java:1226)
         at 
org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:634)
         at 
org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:1088)
         at 
org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:1066)
         at XSLTransform.transform(XSLTransform.java:28)
         at XSLTransform.main(XSLTransform.java:15)
---------
java.util.EmptyStackException
         at java.util.Stack.peek(Stack.java:82)
         at org.jdom.input.SAXHandler.characters(SAXHandler.java:483)
         at 
org.xml.sax.helpers.XMLFilterImpl.characters(XMLFilterImpl.java:614)
         at 
org.apache.xalan.transformer.ResultTreeHandler.characters(ResultTreeHandler.java:479)
         at 
org.apache.xalan.templates.ElemTextLiteral.execute(ElemTextLiteral.java:256)
         at 
org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2243)
         at 
org.apache.xalan.transformer.TransformerImpl.applyTemplateToNode(TransformerImpl.java:2069)
         at 
org.apache.xalan.transformer.TransformerImpl.transformNode(TransformerImpl.java:1171)
         at 
org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:634)
         at 
org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:1088)
         at 
org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:1066)
         at XSLTransform.transform(XSLTransform.java:28)
         at XSLTransform.main(XSLTransform.java:15)
Exception in thread "main"

**************************************************
Xalan code- this works fine:
**************************************************
    File xmlFile = new File(args[0]);
         File xsltFile = new File(args[1]);

         // JAXP reads data using the Source interface
         Source xmlSource = new StreamSource(xmlFile);
         Source xsltSource = new StreamSource(xsltFile);

         // the factory pattern supports different XSLT processors
         TransformerFactory transFact =
                 TransformerFactory.newInstance();
         Transformer trans = transFact.newTransformer(xsltSource);

         trans.transform(xmlSource, new StreamResult(System.out));
     }
}

**********************************************
JDOM code (from jdom/samples)- throws java.util.EmptyStackException:
**********************************************

import org.jdom.*;
import org.jdom.input.*;
import org.jdom.output.*;
import org.jdom.transform.*;
import javax.xml.transform.*;
import javax.xml.transform.stream.*;

public class XSLTransform {

   public static void main(String[] args) throws Exception {
     SAXBuilder builder = new SAXBuilder();
     Document doc = builder.build(args[0]);
     Document doc2 = transform(doc, args[1]);
     XMLOutputter out = new XMLOutputter("  ", true);
     out.setTextNormalize(true);
     out.output(doc2, System.out);
   }

   public static Document transform(Document in, String stylesheet)
                               throws JDOMException {
     try {
       Transformer transformer = TransformerFactory.newInstance()
         .newTransformer(new StreamSource(stylesheet));

       JDOMResult out = new JDOMResult();
       transformer.transform(new JDOMSource(in), out);
       return out.getDocument();
     }
     catch (TransformerException e) {
       throw new JDOMException("XSLT Transformation failed", e);
     }
   }
}
**************************************************
XSL code:
*****************************************************
<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">#VRML V2.0 utf8
NavigationInfo {
   avatarSize	[ 0.25, 1.8, 0.75 ]
   headlight	TRUE
   speed	10
   visibilityLimit	0
}
DEF Spy ProximitySensor {  center	0 1 0  size	1000 1000 1000
  }
Background {
skyAngle	[.3, 2]
skyColor	[ 1 1 .2,1 1 1,0.2 0.2 1]
}
DEF ENTRY Viewpoint {
   position	0 2 0
   orientation	0 1 0 3.4
   fieldOfView	0.785398
   description "Entry"
}
DEF Portobello Viewpoint {
   position	750 2 3200
   orientation	0 1 0 .2
   fieldOfView	0.785398
   description "Portobello"
}
DEF OCONNEL Viewpoint {
   position	1149 2 890
   orientation	0 1 0 .2
   fieldOfView	0.785398
   description "O'CONNEL"
}
DEF DITAUNGIER Viewpoint {
   position	61 0 2000
   orientation	0 1 0 .2
   fieldOfView	0.785398
   description "DIT Aungier Street"
}
DirectionalLight {
   direction	0.707103 -0.707111 1.49012e-007
}
DirectionalLight {
   direction	-0.500003 -0.866023 -9.68575e-008
}

<!--
******************************************************************************************
*here we iterate through the polygon elements, assigning the polygon 
information for each*
*block 																					*
******************************************************************************************
  -->
<xsl:for-each select="vrml/polygon">

<xsl:if test="@id = 1">

DEF Trans_0  Transform {
children Group {
children  DEF _block_0  Shape {
  appearance  Appearance {
  material   Material {
   diffuseColor   1 0.9 0.7
   }
   texture ImageTexture {
   repeatS   TRUE
   repeatT  TRUE
   url  "texture.jpg"
  }
}

          geometry   DEF _0  Extrusion {
          ccw FALSE
          crossSection   [
<!--
*************************************************************
<xsl:value-of select="."/> "." refers to the current element
*************************************************************
-->
<xsl:value-of select="./crossSection"/>
		]		spine   [0 0 0,    0 <xsl:value-of select="@spine"/> 0 ]
		scale   1 1
		orientation   0 0 1  0
		convex   FALSE
     }
   }

  } }
</xsl:if>

<!--
***end of first element- now we iterate through the other elements
-->


<!--
***
here we test for the value of "LOD" attribute. If it is empty, just use the 
following code,
otherwise go to <xsl:otherwise> loop
***
-->
<xsl:choose>
	
		<xsl:when test="@LOD != '' ">


DEF T<xsl:value-of select="@id"/> Transform {
children
	DEF topLOD_<xsl:value-of select="@id"/> LOD  {
  center <xsl:value-of select="@LODcenter"/>
  range [250, 300]
  level[ DEF LODinfile_<xsl:value-of select="@id"/> Transform {
  translation	<xsl:value-of select="@LODtranslation"/>
  rotation	<xsl:value-of select="@LODrotation"/>
  children
DEF Inline_<xsl:value-of select="@id"/> Inline { url "<xsl:value-of 
select="@LOD"/>"}
}         DEF _block_<xsl:value-of select="@id"/> Shape {
             appearance  Appearance {
                 material   Material {
                    diffuseColor   1 0.9 0.7
                 }               texture ImageTexture {
                  repeatS   TRUE
                  repeatT  TRUE
                  url  "texture.jpg"
                 }          }   geometry   DEF _<xsl:value-of 
select="@id"/> Extrusion {
          ccw FALSE
                    crossSection   [
				   <xsl:value-of select="./crossSection"/>
		  ]		spine   [0 0 0,    0 <xsl:value-of select="@spine"/> 0 ]
		scale   1 1
		orientation   0 0 1  0
		convex   FALSE
     }
   }
  ]
   }
  }




		</xsl:when>

		<xsl:otherwise>
		
DEF T<xsl:value-of select="@id"/> Transform {
    children
         DEF _block_<xsl:value-of select="@id"/> Shape {
             appearance  Appearance {
                 material   Material {
                    diffuseColor   1 0.9 0.7
                 }               texture ImageTexture {
                  repeatS   TRUE
                  repeatT  TRUE
                  url  "texture.jpg"
                 }          }   geometry   DEF _<xsl:value-of 
select="@id"/> Extrusion {
          ccw FALSE
		                    crossSection   [

		   <xsl:value-of select="./crossSection"/>
		  ]		spine   [0 0 0,    0 <xsl:value-of select="@spine"/> 0 ]
		scale   1 1
		orientation   0 0 1  0
		convex   FALSE
     }
   }

  }

		</xsl:otherwise>
		
	</xsl:choose>


</xsl:for-each>
</xsl:template>

</xsl:stylesheet>






More information about the jdom-interest mailing list