Solved

Need XSLT parser in java

Posted on 2009-05-11
9
1,002 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 300 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
 
LVL 92

Assisted Solution

by:objects
objects earned 300 total points
ID: 24361916
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

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 200 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

867 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now