• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1039
  • Last Modified:

Need XSLT parser in java

Hi,
I want to prase my below xml using the XSLT , please suggest the some parse which can be used in my jsp code.

Thanks
XML:
 
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<ROWSET>
	<ROW>
		<EMPLOYEE_FULL_NAME>Lamprecht Mr. Mike</EMPLOYEE_FULL_NAME>
		<ASSIGNMENT_NUMBER>201</ASSIGNMENT_NUMBER>
		<EMPLOYEE_NUMBER>201</EMPLOYEE_NUMBER>
		<EMPLOYMENT_CATEGORY>Fulltime-Regular</EMPLOYMENT_CATEGORY>
		<DATE_OF_HIRE>01-JAN-98</DATE_OF_HIRE>
		<GENDER>M</GENDER>
		<ASSIGNMENT_STATUS>Active Assignment</ASSIGNMENT_STATUS>
		<DATE_OF_BIRTH>09-MAY-65</DATE_OF_BIRTH>
		<JOB_NAME>VP300.Vice President</JOB_NAME>
		<POSITION_NAME>(Blanks)</POSITION_NAME>
		<MARITAL_STATUS>Married</MARITAL_STATUS>
		<SUPERVISOR_FULL_NAME>Andretti Mr. Evan</SUPERVISOR_FULL_NAME>
		<PAYROLL_NAME>Vision HR Semi-Monthly</PAYROLL_NAME>
		<GRADE_NAME>100.1.South</GRADE_NAME>
		<ETHNIC_ORIGIN>White</ETHNIC_ORIGIN>
		<SOCIAL_SECURITY_NUMBER>367-98-3283</SOCIAL_SECURITY_NUMBER>
		<LOCATION_NAME>VA- Philadelphia</LOCATION_NAME>
		<GOVERNMENT_REPORTING_ENTITY>Vision Services</GOVERNMENT_REPORTING_ENTITY>
		<ORGANIZATION_NAME>Vision Services</ORGANIZATION_NAME>
		<PAY_BASIS>MONTHLY</PAY_BASIS>
		<PERSON_TYPE>Employee</PERSON_TYPE>
		<ADJUSTED_SERVICE_DATE>(Blanks)</ADJUSTED_SERVICE_DATE>
		<LATEST_HIRE_DATE>01-JAN-98</LATEST_HIRE_DATE>
		<ADDRESS_LINE1>983 Mainstream Ave</ADDRESS_LINE1>
		<ADDRESS_CITY>Atlanta</ADDRESS_CITY>
		<ADDRESS_STATE>Georgia</ADDRESS_STATE>
		<ADDRESS_ZIP>30010</ADDRESS_ZIP>
		<LENGTH_OF_SERVICE>11.35</LENGTH_OF_SERVICE>
	</ROW>
	<ROW>
		<EMPLOYEE_FULL_NAME>Thomas Cindy</EMPLOYEE_FULL_NAME>
		<ASSIGNMENT_NUMBER>226</ASSIGNMENT_NUMBER>
		<EMPLOYEE_NUMBER>226</EMPLOYEE_NUMBER>
		<EMPLOYMENT_CATEGORY>Fulltime-Regular</EMPLOYMENT_CATEGORY>
		<DATE_OF_HIRE>01-JAN-99</DATE_OF_HIRE>
		<GENDER>F</GENDER>
		<ASSIGNMENT_STATUS>Active Assignment</ASSIGNMENT_STATUS>
		<DATE_OF_BIRTH>10-AUG-68</DATE_OF_BIRTH>
		<JOB_NAME>(Blanks)</JOB_NAME>
		<POSITION_NAME>(Blanks)</POSITION_NAME>
		<MARITAL_STATUS>Married</MARITAL_STATUS>
		<SUPERVISOR_FULL_NAME>(Blanks)</SUPERVISOR_FULL_NAME>
		<PAYROLL_NAME>(Blanks)</PAYROLL_NAME>
		<GRADE_NAME>(Blanks)</GRADE_NAME>
		<ETHNIC_ORIGIN>White</ETHNIC_ORIGIN>
		<SOCIAL_SECURITY_NUMBER>222-11-3333</SOCIAL_SECURITY_NUMBER>
		<LOCATION_NAME>VA- Philadelphia</LOCATION_NAME>
		<GOVERNMENT_REPORTING_ENTITY>Vision Services</GOVERNMENT_REPORTING_ENTITY>
		<ORGANIZATION_NAME>Vision Services</ORGANIZATION_NAME>
		<PAY_BASIS>(Blanks)</PAY_BASIS>
		<PERSON_TYPE>Employee</PERSON_TYPE>
		<ADJUSTED_SERVICE_DATE>(Blanks)</ADJUSTED_SERVICE_DATE>
		<LATEST_HIRE_DATE>01-JAN-99</LATEST_HIRE_DATE>
		<ADDRESS_LINE1>4 Saw Mill Ct.</ADDRESS_LINE1>
		<ADDRESS_CITY>Philadelphia</ADDRESS_CITY>
		<ADDRESS_STATE>Pennsylvania</ADDRESS_STATE>
		<ADDRESS_ZIP>19038</ADDRESS_ZIP>
		<LENGTH_OF_SERVICE>10.35</LENGTH_OF_SERVICE>
	</ROW>
	<ROW>
		<EMPLOYEE_FULL_NAME>Che:n Tony</EMPLOYEE_FULL_NAME>
		<ASSIGNMENT_NUMBER>227</ASSIGNMENT_NUMBER>
		<EMPLOYEE_NUMBER>227</EMPLOYEE_NUMBER>
		<EMPLOYMENT_CATEGORY>Fulltime-Regular</EMPLOYMENT_CATEGORY>
		<DATE_OF_HIRE>01-JAN-99</DATE_OF_HIRE>
		<GENDER>M</GENDER>
		<ASSIGNMENT_STATUS>Active Assignment</ASSIGNMENT_STATUS>
		<DATE_OF_BIRTH>28-SEP-63</DATE_OF_BIRTH>
		<JOB_NAME>(Blanks)</JOB_NAME>
		<POSITION_NAME>(Blanks)</POSITION_NAME>
		<MARITAL_STATUS>Married</MARITAL_STATUS>
		<SUPERVISOR_FULL_NAME>Thomas Cindy</SUPERVISOR_FULL_NAME>
		<PAYROLL_NAME>(Blanks)</PAYROLL_NAME>
		<GRADE_NAME>(Blanks)</GRADE_NAME>
		<ETHNIC_ORIGIN>White</ETHNIC_ORIGIN>
		<SOCIAL_SECURITY_NUMBER>149-21-9421</SOCIAL_SECURITY_NUMBER>
		<LOCATION_NAME>VA- Philadelphia</LOCATION_NAME>
		<GOVERNMENT_REPORTING_ENTITY>Vision Services</GOVERNMENT_REPORTING_ENTITY>
		<ORGANIZATION_NAME>Vision Services</ORGANIZATION_NAME>
		<PAY_BASIS>(Blanks)</PAY_BASIS>
		<PERSON_TYPE>Employee</PERSON_TYPE>
		<ADJUSTED_SERVICE_DATE>(Blanks)</ADJUSTED_SERVICE_DATE>
		<LATEST_HIRE_DATE>01-JAN-99</LATEST_HIRE_DATE>
		<ADDRESS_LINE1>14 Broad St.</ADDRESS_LINE1>
		<ADDRESS_CITY>Philadelphia</ADDRESS_CITY>
		<ADDRESS_STATE>Pennsylvania</ADDRESS_STATE>
		<ADDRESS_ZIP>19092</ADDRESS_ZIP>
		<LENGTH_OF_SERVICE>10.35</LENGTH_OF_SERVICE>
	</ROW>
	<ROW>
		<EMPLOYEE_FULL_NAME>Noe Renee</EMPLOYEE_FULL_NAME>
		<ASSIGNMENT_NUMBER>228</ASSIGNMENT_NUMBER>
		<EMPLOYEE_NUMBER>228</EMPLOYEE_NUMBER>
		<EMPLOYMENT_CATEGORY>Fulltime-Regular</EMPLOYMENT_CATEGORY>
		<DATE_OF_HIRE>01-JAN-99</DATE_OF_HIRE>
		<GENDER>F</GENDER>
		<ASSIGNMENT_STATUS>Active Assignment</ASSIGNMENT_STATUS>
		<DATE_OF_BIRTH>12-FEB-68</DATE_OF_BIRTH>
		<JOB_NAME>MGR500.Manager</JOB_NAME>
		<POSITION_NAME>510.PROJECT MANAGER</POSITION_NAME>
		<MARITAL_STATUS>Married</MARITAL_STATUS>
		<SUPERVISOR_FULL_NAME>Ang Ms. Lay Kuan</SUPERVISOR_FULL_NAME>
		<PAYROLL_NAME>Vision Monthly</PAYROLL_NAME>
		<GRADE_NAME>(Blanks)</GRADE_NAME>
		<ETHNIC_ORIGIN>Black or African American</ETHNIC_ORIGIN>
		<SOCIAL_SECURITY_NUMBER>214-19-4219</SOCIAL_SECURITY_NUMBER>
		<LOCATION_NAME>VS- Washington DC</LOCATION_NAME>
		<GOVERNMENT_REPORTING_ENTITY>Vision Operations</GOVERNMENT_REPORTING_ENTITY>
		<ORGANIZATION_NAME>Vision Administration</ORGANIZATION_NAME>
		<PAY_BASIS>MONTHLY</PAY_BASIS>
		<PERSON_TYPE>Employee</PERSON_TYPE>
		<ADJUSTED_SERVICE_DATE>(Blanks)</ADJUSTED_SERVICE_DATE>
		<LATEST_HIRE_DATE>01-JAN-99</LATEST_HIRE_DATE>
		<ADDRESS_LINE1>17 Chestnut St.</ADDRESS_LINE1>
		<ADDRESS_CITY>Philadelphia</ADDRESS_CITY>
		<ADDRESS_STATE>Pennsylvania</ADDRESS_STATE>
		<ADDRESS_ZIP>19092</ADDRESS_ZIP>
		<LENGTH_OF_SERVICE>10.35</LENGTH_OF_SERVICE>
	</ROW>
</ROWSET>
 
and XSL:
 
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
    <xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>
    <xsl:template match="ROWSET">
        <chart>
            <xsl:for-each-group select="ROW" group-by="ETHNIC_ORIGIN">
                <set label="{ETHNIC_ORIGIN}" value="{count(current-group())}"/>
            </xsl:for-each-group>
        </chart>
    </xsl:template>
</xsl:stylesheet>

Open in new window

0
ramadevimandala
Asked:
ramadevimandala
  • 4
  • 4
3 Solutions
 
objectsCommented:
the following shows code needed for the transformation

http://helpdesk.objects.com.au/java/how-to-transform-xml-using-xsl

0
 
ramadevimandalaAuthor Commented:
Hi,

Thank u for the help.

I am using xslt 2.0 version for my XSL:

so the code in above link generating an error:
ERROR:  'Unsupported XSL element 'http://www.w3.org/1999/XSL/Transform:for-each-group''
javax.xml.transform.TransformerException: java.lang.RuntimeException: Unsupported XSL element 'http://www.w3.org/1999/XSL/Transform:for-each-group'

any suggestions pls?
0
 
objectsCommented:
what parser implementation are you using? need one thats 2.0 compliant
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
objectsCommented:
0
 
ramadevimandalaAuthor Commented:
I am using saxonsa9-1-0-6j.. but the code

  TransformerFactory factory = TransformerFactory.newInstance();
                Templates template = factory.newTemplates(
                   new StreamSource(new FileInputStream("detailed.xslt")));
                Transformer transformer = template.newTransformer();
                Source source = new StreamSource(new FileInputStream("second.xml"));
                Result result = new StreamResult(new FileOutputStream("summary.xml"));
                transformer.transform(source, result);

all classes are from DOM  which is not supporting xslt 2.0
so need to use similar classes in SAX api.
0
 
objectsCommented:
0
 
ChristoferDutzCommented:
I think you are not actually using the Saxon transformer, as you usually hafe to register it first.

System.setProperty("javax.xml.transform.TransformerFactory",  
 "net.sf.saxon.TransformerFactoryImpl");  

Try the following code, I got it from:
http://blog.msbbc.co.uk/2007/06/simple-saxon-java-example.html
public static void myTransformer (String sourceID, String xslID)  
throws TransformerException, TransformerConfigurationException {  
  
        // Create a transform factory instance.  
        TransformerFactory tfactory = TransformerFactory.newInstance();  
  
 // Create a transformer for the stylesheet.  
 Transformer transformer = tfactory.newTransformer(new StreamSource(new File(xslID)));  
  
 // Transform the source XML to System.out.  
 transformer.transform(new StreamSource(new File(sourceID)),  
    new StreamResult(System.out));  
}  
  
The "void main" bit:  
  
public static void main(String args[]) {  
  
 // set the TransformFactory to use the Saxon TransformerFactoryImpl method   
 System.setProperty("javax.xml.transform.TransformerFactory",  
 "net.sf.saxon.TransformerFactoryImpl");  
    
  
 String foo_xml = "xml/foo.xml"; //input xml  
 String foo_xsl = "xsl/foo.xsl"; //input xsl  
  
 try {  
         myTransformer (foo_xml, foo_xsl);  
 } catch (Exception ex) {  
      handleException(ex);  
 }  
  
}  

Open in new window

0
 
ramadevimandalaAuthor Commented:
Thank you very much...
I have just added
// set the TransformFactory to use the Saxon TransformerFactoryImpl method  
 System.setProperty("javax.xml.transform.TransformerFactory",  
 "net.sf.saxon.TransformerFactoryImpl");

and transform works fine.
0
 
ramadevimandalaAuthor Commented:
Thank you
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now