[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Need XSLT parser in java

Posted on 2009-05-11
9
Medium Priority
?
1,033 Views
Last Modified: 2013-11-18
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
Comment
Question by:ramadevimandala
  • 4
  • 4
9 Comments
 
LVL 92

Accepted Solution

by:
objects earned 1200 total points
ID: 24361841
the following shows code needed for the transformation

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

0
 

Author Comment

by:ramadevimandala
ID: 24361870
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
 
LVL 92

Expert Comment

by:objects
ID: 24361903
what parser implementation are you using? need one thats 2.0 compliant
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 92

Assisted Solution

by:objects
objects earned 1200 total points
ID: 24361916
0
 

Author Comment

by:ramadevimandala
ID: 24361946
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
 
LVL 92

Expert Comment

by:objects
ID: 24361976
0
 
LVL 20

Assisted Solution

by:ChristoferDutz
ChristoferDutz earned 800 total points
ID: 24362048
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
 

Author Comment

by:ramadevimandala
ID: 24362372
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
 

Author Closing Comment

by:ramadevimandala
ID: 31580426
Thank you
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Create a Windows 10 custom Image with custom task bar and custom start menu using XML for deployment.
The viewer will learn how to count occurrences of each item in an array.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question