You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-dev@xmlgraphics.apache.org by "Rich Van Deren (万达仁)" <rv...@mac.com> on 2002/04/16 16:11:37 UTC

Confused with Fop extensions, distinct.

I have tried to read the docs.   I had used distinct before but not in 
an embedded application.

Function not supported.   Is my error message.

I have inclued my stack Trace.  My includes in my application. and my 
stylesheet.
Thanks in advance for any help you can give.

<xsl:template match="ClientHistory">  distinct used here.

Trace:
java.lang.RuntimeException: Function not supported!
	at org.apache.xml.utils.UnImplNode.error(UnImplNode.java:87)
	at org.apache.xml.utils.UnImplNode.getNodeValue(UnImplNode.java:570)
	at org.apache.xalan.lib.Extensions.distinct(Extensions.java:210)
	at java.lang.reflect.Method.invoke(Native Method)
	at 
org.apache.xalan.extensions.ExtensionHandlerJavaClass.callFunction
(ExtensionHandlerJavaClass.java:332)
	at 
org.apache.xalan.extensions.ExtensionsTable.extFunction(ExtensionsTable.java:
253)
	at 
org.apache.xpath.functions.FuncExtFunction.execute(FuncExtFunction.java:141)
	at org.apache.xpath.XPath.execute(XPath.java:269)
	at 
org.apache.xalan.templates.ElemForEach.transformSelectedNodes
(ElemForEach.java:388)
	at org.apache.xalan.templates.ElemForEach.execute(ElemForEach.java:228)
	at 
org.apache.xalan.transformer.TransformerImpl.executeChildTemplates
(TransformerImpl.java:2154)
	at 
org.apache.xalan.transformer.TransformerImpl.executeChildTemplates
(TransformerImpl.java:2097)
	at 
org.apache.xalan.templates.ElemLiteralResult.execute(ElemLiteralResult.java:
739)
	at 
org.apache.xalan.templates.ElemForEach.transformSelectedNodes
(ElemForEach.java:495)
	at 
org.apache.xalan.templates.ElemApplyTemplates.execute(ElemApplyTemplates.java:
193)
	at 
org.apache.xalan.templates.ElemForEach.transformSelectedNodes
(ElemForEach.java:495)
	at 
org.apache.xalan.templates.ElemApplyTemplates.execute(ElemApplyTemplates.java:
193)
	at 
org.apache.xalan.transformer.TransformerImpl.executeChildTemplates
(TransformerImpl.java:2154)
	at 
org.apache.xalan.transformer.TransformerImpl.executeChildTemplates
(TransformerImpl.java:2097)
	at 
org.apache.xalan.templates.ElemLiteralResult.execute(ElemLiteralResult.java:
739)
	at 
org.apache.xalan.transformer.TransformerImpl.executeChildTemplates
(TransformerImpl.java:2154)
	at 
org.apache.xalan.transformer.TransformerImpl.executeChildTemplates
(TransformerImpl.java:2097)
	at 
org.apache.xalan.templates.ElemLiteralResult.execute(ElemLiteralResult.java:
739)
	at 
org.apache.xalan.transformer.TransformerImpl.executeChildTemplates
(TransformerImpl.java:2154)
	at 
org.apache.xalan.transformer.TransformerImpl.executeChildTemplates
(TransformerImpl.java:2097)
	at 
org.apache.xalan.templates.ElemLiteralResult.execute(ElemLiteralResult.java:
739)
	at 
org.apache.xalan.transformer.TransformerImpl.executeChildTemplates
(TransformerImpl.java:2154)
	at 
org.apache.xalan.transformer.TransformerImpl.executeChildTemplates
(TransformerImpl.jav

stylesheet:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
version="1.0"
	xmlns:fo="http://www.w3.org/1999/XSL/Format"
	xmlns:xalan="http://xml.apache.org/xalan"
	exclude-result-prefixes="xalan"
	>
<xsl:output method="xml"/>

<xsl:template match="/">

	<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">

		<!-- defines page layout -->
		<fo:layout-master-set>

			<fo:simple-page-master master-name="simple"
							page-height="29.7cm"
							page-width="21cm"
							margin-top="1.5cm"
							margin-bottom="2cm"
							margin-left="2.5cm"
							margin-right="2.5cm">
				<fo:region-body margin-top="1cm"/>
				<fo:region-before extent="1.5cm"/>
				<fo:region-after extent="1.5cm"/>
			</fo:simple-page-master>
		</fo:layout-master-set>

		<fo:page-sequence master-reference ="simple">
			<fo:static-content flow-name="xsl-region-before">
				<fo:block text-align="end"
							font-size="10pt"
							font-family="serif"
							line-height="14pt" >
My Resume - p. <fo:page-number/>
				</fo:block>
			</fo:static-content>
			<fo:flow flow-name="xsl-region-body">
<xsl:apply-templates/>
</fo:flow>
		</fo:page-sequence>
	</fo:root>
</xsl:template>
<xsl:template match="TestSummary"></xsl:template>
<xsl:template match="Copyright"></xsl:template>
<xsl:template match="DefaultCharge"></xsl:template>
<xsl:template match="ResumePdf"></xsl:template>
<xsl:template match="ResumeHtml"></xsl:template>
<xsl:template match="ResumeLanguage"></xsl:template>
<xsl:template match="ResumeProfession"></xsl:template>
<xsl:template match="MovieBaseUriString"></xsl:template>
<xsl:template match="InterviewMovieUriString"></xsl:template>
<xsl:template match="CasualPhotoMovieUriString"></xsl:template>
<xsl:template match="FormalPhotoMovieUriString"></xsl:template>
<xsl:template match="Worker">
<fo:block font-size="18pt"
             font-family="sans-serif"
             line-height="24pt"
             space-before.optimum="15pt"
             space-after.optimum="15pt"
             background-color="blue"
             color="white"
             text-align="center"
             >
<xsl:apply-templates 
select="Contact/PersonName/FullName"/><xsl:text></xsl:text>
</fo:block>
<fo:block font-size="12pt"
             font-family="sans-serif"
             line-height="14pt"
             space-before.optimum="10pt"
             space-after.optimum="9pt"
             text-align="start"
             padding-top="3pt">
       <fo:list-block provisional-distance-between-starts="4.0cm"
                      provisional-label-separation=".35cm">
         <fo:list-item >
		<fo:list-item-label start-indent="0mm" end-indent="label-end()">
		<fo:block text-align="end">Work:</fo:block>
		</fo:list-item-label>
		<fo:list-item-body start-indent="body-start()">
		    <fo:block >
		  <xsl:apply-templates 
select="Contact/Phones/WorkPhone"/><xsl:text></xsl:text>
		    </fo:block>
		</fo:list-item-body>
	</fo:list-item>
         <fo:list-item>
		<fo:list-item-label start-indent="0mm" end-indent="label-end()">
		<fo:block text-align="end">Home: </fo:block>
		</fo:list-item-label>
		<fo:list-item-body start-indent="body-start()">
		    <fo:block>
	<xsl:apply-templates 
select="Contact/Phones/HomePhone"/><xsl:text></xsl:text>
		    </fo:block>
	</fo:list-item-body>
	</fo:list-item>
	<fo:list-item>
		<fo:list-item-label start-indent="0mm" end-indent="label-
end()"><fo:block>  </fo:block>
		</fo:list-item-label>
		<fo:list-item-body start-indent="body-start()">
		    <fo:block>
		  <xsl:for-each select="Contact/HomePostalAddress/PostalAddress">
				<xsl:value-of select="AddressLines/AddressLine[1]"/>
<xsl:if test="AddressLines/AddressLine[2]">
<xsl:value-of select="concat(', 
',AddressLines/AddressLine[2])"/></xsl:if>
<xsl:value-of select="concat(', ',City)"/><xsl:value-of 
select="concat(', ',Region)"/><xsl:value-of select="concat(', 
',PostalCode)"/>
	</xsl:for-each>
                     </fo:block>
	</fo:list-item-body>
	</fo:list-item>
  	<fo:list-item start-indent="0mm" end-indent="label-end()">
  		<fo:list-item-label><fo:block>  </fo:block>
  		</fo:list-item-label>
  		<fo:list-item-body start-indent="body-start()">
  		    <fo:block>
  		  <xsl:for-each select="Contact/HomePostalAddress/PostalAddress">
  	<xsl:value-of select="Country"/>
  	</xsl:for-each>
                      </fo:block>
  	</fo:list-item-body>
	</fo:list-item>
  	<fo:list-item>
		<fo:list-item-label start-indent="0mm" end-indent="label-end()">
		<fo:block text-align="end">Email: </fo:block>
		</fo:list-item-label>
		<fo:list-item-body start-indent="body-start()">
		    <fo:block>
		   	<xsl:element name="fo:basic-link">
		   		<xsl:attribute name="external-
destination"><xsl:value-of select="concat('mailto:',Contact/Email)"/>  
</xsl:attribute>
				<xsl:value-of select="Contact/Email"/></xsl:element>
		   </fo:block>
		</fo:list-item-body>
	 </fo:list-item>
          <fo:list-item>
  		<fo:list-item-label start-indent="0mm" end-indent="label-end()">
  		<fo:block text-align="end">Resume URLs: </fo:block>
  		</fo:list-item-label>
  		<fo:list-item-body start-indent="body-start()">
  		    <fo:block>
			<xsl:element name="fo:basic-link">
				<xsl:attribute name="external-
destination">http://home.pacbell.net/vanderen/Resume.html</xsl:attribute>
vanderne pacbell Resume html	</xsl:element>
</fo:block>
  		</fo:list-item-body>
  	</fo:list-item>
  	         <fo:list-item>
	 		<fo:list-item-label start-indent="0mm" end-indent="label-end()">
	 		<fo:block> </fo:block>
	 		</fo:list-item-label>
	 		<fo:list-item-body start-indent="body-start()">
	 		    <fo:block>
				<xsl:element name="fo:basic-link">
					<xsl:attribute name="external-
destination">http://home.pacbell.net/vanderen/Resume.pdf</xsl:attribute>
vanderne pacbell Resume.pdf</xsl:element>
</fo:block>
	 		</fo:list-item-body>
  	</fo:list-item>

	</fo:list-block>
</fo:block>	
</xsl:template>


<xsl:template match="EducationInfo">
<fo:block font-size="18pt"
             font-family="sans-serif"
             line-height="24pt"
             space-before.optimum="15pt"
             space-after.optimum="15pt"
             background-color="blue"
             color="white"
             text-align="center"
             >
Education
</fo:block>
<xsl:for-each select="SchoolDurations/SchoolDuration">
<fo:block font-size="12pt"
             font-family="sans-serif"
             line-height="14pt"
             space-before.optimum="4pt"
             space-after.optimum="3pt"
             text-align="start"
             padding-top="3pt">

<xsl:element name="fo:basic-link">
	<xsl:attribute name="external-destination"><xsl:value-of 
select="SchoolWebSite"/></xsl:attribute>
	<xsl:value-of select="SchoolName"/></xsl:element>

<xsl:value-of select="concat(', 
',substring(SchoolStartDate,8,4),'-',substring(SchoolEndDate,8,4),', 
',Degree,', ',GradYear,', ',./Major)"/>
</fo:block>

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

<xsl:template match="Experiences">

<fo:block font-size="18pt"
             font-family="sans-serif"
             line-height="24pt"
             space-before.optimum="15pt"
             space-after.optimum="15pt"
             background-color="blue"
             color="white"
             text-align="center"
             >
Experience
</fo:block>
<xsl:for-each select="Experience">
    <fo:block font-size="12pt"
             font-family="sans-serif"
             line-height="13pt"
             space-after.optimum="3pt"
             space-before.optimum="3pt"
             text-align="justify">

<xsl:value-of select="text()"/>
</fo:block>
</xsl:for-each>


</xsl:template>

<xsl:template match="ClientHistory">
<fo:block font-size="18pt"
             font-family="sans-serif"
             line-height="24pt"
             space-before.optimum="15pt"
             space-after.optimum="15pt"
             background-color="blue"
             color="white"
             text-align="center"
             >
Client History
</fo:block>
    <fo:block font-size="12pt"
             font-family="sans-serif"
             line-height="13pt"
             space-after.optimum="3pt"
             space-before.optimum="3pt"
             text-align="justify">
<xsl:for-each 
select="xalan:distinct(/Resume/WorkHistoryInfo/WorkDurations/WorkDuration/
ClientName[text()])">
<xsl:sort select="."/>
<xsl:value-of select="."/><xsl:if test="not( position()=last() )">, 
</xsl:if>
</xsl:for-each>
</fo:block>
</xsl:template>

<xsl:template match="Objectives">

<fo:block font-size="18pt"
             font-family="sans-serif"
             line-height="24pt"
             space-before.optimum="15pt"
             space-after.optimum="15pt"
             background-color="blue"
             color="white"
             text-align="center"
             >
Objectives
</fo:block>

<xsl:for-each select="Objective">
    <fo:block font-size="12pt"
             font-family="sans-serif"
             line-height="13pt"
             space-after.optimum="3pt"
             space-before.optimum="3pt"
             text-align="justify">
<xsl:value-of select="text()"/>
</fo:block>

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

<xsl:template match="AccessPolicyInfo"></xsl:template>
<!-- p  [not(code)] -->
<xsl:template match ="p">
    <fo:block font-size="11pt"
             font-family="sans-serif"
             line-height="13pt"
             space-after.optimum="3pt"
             space-before.optimum="3pt"
             text-align="justify">
      <xsl:apply-templates/>
    </fo:block>
</xsl:template>



</xsl:stylesheet>

myApp's java class:

/* ResumeFop */



//---------------------------------------
//  ResumeFop.java
//  MyResume
//
//  Created by Richard Van Deren on Wed Mar 13 2002.
//
// change m


import com.apple.cocoa.foundation.*;
import com.apple.cocoa.application.*;
import java.io.*;
import java.net.*;
//
import org.apache.xerces.parsers.DOMParser;
// Imported TraX classes
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.stream.StreamSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerConfigurationException;
// SAX which version of xerces? 123 or 200
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
// Xerces
import org.apache.xerces.parsers.SAXParser;
// Xalan
import org.apache.xalan.lib.Extensions;
import org.apache.xalan.extensions.*;
import org.apache.xpath.axes.LocPathIterator;
// FOP
import org.apache.fop.apps.Driver;
import org.apache.fop.apps.Options;
import org.apache.fop.apps.Version;
import org.apache.fop.apps.FOPException;
import org.apache.fop.apps.InputHandler;
import org.apache.fop.apps.XSLTInputHandler;
import org.apache.fop.configuration.Configuration;
// LogKit
import org.apache.log.*;
import org.apache.log.format.*;
import org.apache.log.output.*;
import org.apache.log.output.io.*;
// Batik
import org.apache.batik.util.XMLResourceDescriptor;


public class ResumeFop extends NSObject {
     public static final int RENDER_PDF = 1;
     public static final int JUNK = 9;
     public static String userConfig = 
"/Users/vanderen/ProjectSource/Fop/Fop-0.20.3rc/conf/userconfig.xml";
     public static String outFile = "/Users/vanderen/ResumeJunk.pdf";
     public static String defaultStylesheetFile = 
"/Users/vanderen/Resume/ResumeV2.xsl";
     public  String defaultStylesheetURL = "ResumeV2.xsl";
     public  String showPdfWindowNotification = 
"ShowPdfWindowNotification";
     public  String foOutput;
     public  FileOutputStream myPdfFileOutputStream;
     public  ByteArrayOutputStream myPdfOutputStream;
     private URL anURL;
     public  SAXParser 	parser;
     public  File 	userConfigFile;
     public  Options 	options;
     public  Logger 	log;
// Data from files
     private NSData	dataFromResumeMarkupFile;		
     private NSData	dataFromPdfFile;		
     private NSData	myStylesheetData;		
     public  NSPDFImageRep 	resumePdfRep;
     public  NSRect		resumePdfRect;	
     public  NSMatrix	formattingObjectsOutputSwitch;	
     public  NSMatrix	stylesheetOutputSwitch;	

// IB Objects on main window
     public  int 	fopOutputType;
     public  NSMatrix 	formattingObjectsOutputTypeSwitch;
     public  NSButton 	createOutputButton;
     public  NSButton 	createFormattingObjectsButton;
     public  NSWindow resumePdfWindow;
     public  NSTextField	mainMessageField;


     public  NSImageView 	resumeImageView;
     public  NSImage 		resumeImage;
     public  NSTextView 		resumeMLTextView;
     public  NSTextView 		speechRecognitionTextView;
     public  NSTextView 		resumeStylesheetTextView;	
     public  NSTextView 		resumeFormattingObjectsTextView;	
     public  NSTextView 		resumeHtmlTextView;
     public  NSImageView 	resumePdfView;	
     public  NSImage 		resumePdfImage;	
	

     public ResumeFop() {
         super();
         // default output type
         fopOutputType = RENDER_PDF;
         this.setMyLogger();
         userConfigFile = new File(userConfig);
     }


     public void setMyLogger() {
         Hierarchy hierarchy = Hierarchy.getDefaultHierarchy();
         PatternFormatter formatter = new PatternFormatter(
         "[%{priority}]: %{message}\n%{throwable}" );

         LogTarget target = null;
         target = new StreamTarget(System.out, formatter);

         hierarchy.setDefaultLogTarget(target);
         log = hierarchy.getLoggerFor("fop");
         log.setPriority(Priority.INFO);
     }
     public void readDefaultStylesheet(Object sender)
     {
         myStylesheetData = new NSData();
         myStylesheetData.dataWithContentsOfMappedFile(new 
File(defaultStylesheetFile));
         
resumeStylesheetTextView.replaceCharactersInRangeWithRTF(this.rangeOfXslDocument(
), myStylesheetData);
     }
     public void writeDefaultStylesheet(Object sender)
     {
         boolean atomically = true;
     }
     public void selectFopOutputType(Object sender)
{

         switch (formattingObjectsOutputTypeSwitch.selectedRow()) {
             case 0:
                 fopOutputType = Driver.RENDER_PDF;
                 break;
             case 1:
                 fopOutputType = Driver.RENDER_XML;
                 break;
             case 2:
                 mainMessageField.setStringValue("Richtext not support 
now. Using Text");
                 fopOutputType = Driver.RENDER_TXT;
                break;
             case 3:
                 fopOutputType = Driver.RENDER_TXT;
                 break;
             case 4:
                 fopOutputType = Driver.RENDER_PS;
                 break;
             default:
                 fopOutputType = Driver.RENDER_PDF;


         }
}
public void createFopOutput(Object sender)
       throws FOPException
{
     int bufferSize = 50000;
         char[] foBuffer;

         foBuffer = 
resumeFormattingObjectsTextView.string().toCharArray();
         CharArrayReader myFoInputStream = new CharArrayReader(foBuffer);
         InputSource myFoInputSource = new InputSource(myFoInputStream);

         myPdfOutputStream = new ByteArrayOutputStream();
         File outputFile = new File("/Users/vanderen/myResume/junk.pdf");
          try{
         myPdfFileOutputStream = new FileOutputStream(outputFile);
          }
          catch (FileNotFoundException ex) {
              mainMessageField.setStringValue("You have a file error.");
              throw new FOPException(ex);
          }


          try{
              Driver driver = new Driver ( myFoInputSource, 
myPdfFileOutputStream );
              parser = new SAXParser();
              driver.setRenderer(new 
org.apache.fop.render.pdf.PDFRenderer());
              driver.render(parser, myFoInputSource);
              driver.reset();
             if (fopOutputType == Driver.RENDER_TXT)
                 
speechRecognitionTextView.replaceCharactersInRange(this.rangeOfSpeechDocument(
), myPdfOutputStream.toString());
             if (fopOutputType == Driver.RENDER_PDF) {
                 NSImage resumeImage = new NSImage();
                 NSData myPdfData = new 
NSData(myPdfOutputStream.toByteArray());

                 NSPDFImageRep myPdfImageRep = new 
NSPDFImageRep(myPdfData);
                 resumeImage.addRepresentation(myPdfImageRep);
                 resumeImageView.setImage(resumeImage);
             }


             }
          catch (Exception ex) {
              mainMessageField.setStringValue("You have an error.");
              throw new FOPException(ex);
          }


         mainMessageField.setStringValue("Here is your output");
         System.gc();
         System.runFinalization();
// try to reset cocoa        super();

}
public void createFormattingObjects(Object sender)
       throws TransformerException
     {
         char[] xmlBuffer;
         xmlBuffer = resumeMLTextView.string().toCharArray();
         CharArrayReader myXmlInputStream = new 
CharArrayReader(xmlBuffer);
         InputSource myXmlInputSource = new InputSource(myXmlInputStream);

         char[] xslBuffer;
         xslBuffer = resumeStylesheetTextView.string().toCharArray();
         CharArrayReader myXslInputStream = new 
CharArrayReader(xslBuffer);
         InputSource myXslInputSource = new InputSource(myXslInputStream);

         ByteArrayOutputStream myFoOutputStream = new 
ByteArrayOutputStream();


          try{
             TransformerFactory tFactory = 
TransformerFactory.newInstance();
             Transformer transformer = tFactory.newTransformer(new 
StreamSource(myXslInputStream));
             transformer.transform(new StreamSource(myXmlInputStream), 
new StreamResult(myFoOutputStream));

             
resumeFormattingObjectsTextView.replaceCharactersInRange(this.rangeOfFoDocument(
), myFoOutputStream.toString());
             }
         catch (Exception ex) {
             throw new TransformerException(ex);
             }
     mainMessageField.setStringValue("Here is your Formatting Objects");
         System.gc();
         System.runFinalization();
}
     // ============================================================
     // Utility Methods : Misc, and Target/Actions Methods
     // ============================================================

     private NSRange rangeOfEntireDocument() {
	// Convenience method: Compute and return the range that 
encompasses the entire document.
	int length = 0;
	if (resumeMLTextView.string()!=null) {
	    length = resumeMLTextView.string().length();
	}
	return new NSRange(0,length);
     }
private NSRange rangeOfFoDocument() {
     // Convenience method: Compute and return the range that encompasses 
the entire document.
     int length = 0;
     if (resumeFormattingObjectsTextView.string()!=null) {
         length = resumeFormattingObjectsTextView.string().length();
     }
     return new NSRange(0,length);
}
private NSRange rangeOfSpeechDocument() {
     // Convenience method: Compute and return the range that encompasses 
the entire document.
     int length = 0;
     if (speechRecognitionTextView.string()!=null) {
         length = speechRecognitionTextView.string().length();
     }
     return new NSRange(0,length);
}

private NSRange rangeOfXslDocument() {
     // Convenience method: Compute and return the range that encompasses 
the entire document.
     int length = 0;
     if (resumeStylesheetTextView.string()!=null) {
         length = resumeStylesheetTextView.string().length();
     }
     return new NSRange(0,length);
}


}


300 Refugio Rd
Santa Cruz, CA 95060-2348
831-469-4348

Instant Messaging: Yahoo: rhvanderen AOL/Netscape rhvanderen MSN: 
rvanderen@mac.com ICQ: 31286953