Xml xslt and java
To obtain a HTML form from a xsd (xml schema) I thought I must use a parser to parse the schema and extract field info (how many fields needed and which type) to create the form to add records to a simple XML DB, like:
<db>
<rec id="0">
</rec>
</db>
but someone suggested me to use a XSLT, but I don't figure I can use it... and anyway... I must use xalan to apply that xslt to my xml schema to translate it, right?
suggestions, tips and so on are really appreciated!
Thank you in advance!
Dakkar
javax.xml.transform:
javax.xml.transform.stream:
Source xsltSource = new StreamSource(new File("mytemplate.xslt")); // e.g. from XSLT file
Transformer t = TransformerFactory.newInstance().newTransformer(xsltSource);
t.transform(source,result); // where source is your schema doc and result is the target (a stream, a file ...)
Similar Messages
-
Simple XML to Text onversion using XSLT and Java?
Hi all!
I'm completly new to using XSLT and Java and are trying to convert a XML file into a ordinary Textfile that I am gonna import into another application.
I started up writing a ordinary XML parser in Java which interpreted the XML file, but realized later on that it was possible to do with a ordinary XSLT.
So far it is a 2-step process right now, I've tied my XSLT to the XML file and then just open the XML file up in a ordinary browser and then get the result.
I found an example (http://www.onjava.com/pub/a/onjava/excerpt/java_xslt_ch5/index.html?page=3) where u hook up a XML file and a XSL file separately and the process it, and dump it to Stdout. But do I need to hook up a XSL file like this when the XML file is tied to a XSL file internally?Just to give you an example to show you how easy it is: http://www.daniweb.com/forums/thread137587.html
-
RESOURCE_NOT_FOUND for XSLT and Java Mappings (SXMB_MONI)
Experts,
I need your opinion / experience about a problem that we have been facing here:
XI 3.0 was upgraded to PI 7.0, but since then all interfaces that uses XSLT and Java Mappings throws a RESOURCE_NOT_FOUND error in SXMB_MONI only in the production environment.
We found SAP Note 951318 that describes exactly the scenario we have here. The note also inform that the issue is solved at SP 07 (for PI 7.0).
The problem is that we find out that abap and java instance are with different SP ( SP 13 for abap and SP 09 for java) after XI upgrade to 7.0, since they had a error at java instance.
Have anyone of you facing with this problem?
I believe that even having a SP greater than 07 (as sap note 951318 requires), as we have an difference between abap and java SP, this issue might have been causing the problem.
Points will be given.
Regards,
DanielaYes, thats true. As you can see,
In XI 3.0 (SAP Netweaver'04), the issue is solved in:
SP 18,
SP 17, patch 1 (archive SAPXITOOL17_1. sca for XI Tools)
SP 16, patch 4 (archive SAPXITOOL16_4.sca for XI Tools).
you need to import and put a patch if you are using XI 3.0. but in your case it is PI 7.0.
So please check out the SAP Note : 950608 and download SP 07,patch 2 (archive SAPXITOOL07_2.sca for XI Tools).and Note 952402 .
Regards
Aashish Sinha
PS : reward points if helpful -
Hello friends,
Can any one know that how to create a XSLT and Java Mapping file(Jar File).
I am not able to find any of the example so if you create a example or find some where please let me know on that How to create such files...
Thanks...
Gaurav JainHi,
I am trying to invoke a Java Extension Function from a XSLT. I added both the class file and the XSLT file to a folder, then zipped the entire folder and uploaded into the Archive for my Interface MApping.
The CLASS gets loaded but the runtime engine gives an error when calling the JAVA Function.
Here is what it says:
Creating mapping sequence with 2 steps. --- Creating Java mapping Deliveries/stringHandler --- Creating mapping sequence with 2 steps. --- Creating XSLT mapping Deliveries/test1 --- Using MappingResolver with context URL /sapmnt/XD1/global/xi/mapping/http%3A%2F%2Fwolterskluwer%2Ecom%2Fxi%2F wk_midas_deliveries%2Ftest/cd2e6820267511d9cb52c3c5143c3524/ --- Loaded class Deliveries.stringHandler --- com.sap.aii.ibrun.server.map.MappingRuntimeException: at com.sap.aii.ibrun.server.map.MappingRuntimeException.code_STYLESHEET_OR_CLASS_NOT_FOUND(MappingRuntimeException.java:91) at com.sap.aii.ibrun.server.map.RUMappingJava.instantiate(RUMappingJava.java:168) at com.sap.aii.ibrun.server.map.RUMappingJava.execute(RUMappingJava.java:41) at com.sap.aii.ibrun.server.map.RUSequence.execute(RUSequence.java:50) at com.sap.aii.ibrun.server.map.RURunner.run(RURunner.java:58) at com.sap.aii.ibrun.server.map.RUManager.run(RUManager.java:66) at com.sap.aii.ibrun.sbeans.map.MappingRequestHandler.handleRequest(MappingRequestHandler.java:67) at com.sap.aii.ibrun.sbeans.map.MappingServiceImpl.processFunction(MappingServiceImpl.java:83) at com.sap.aii.ibrun.sbeans.map.XMappingServiceObjectImpl0.processFunction(XMappingServiceObjectImpl0.java:24) at com.sap.aii.ibrun.sbeans.map.MappingServiceKey.processFunction(MappingServiceKey.java:10) at java.lang.reflect.Method.invoke(Native Method) at com.inqmy.services.rfcengine.RFCDefaultRequestHandler.invokeBean(RFCDefaultRequestHandler.java:83) at com.inqmy.services.rfcengine.RFCDefaultRequestHandler.handleRequest(RFCDefaultRequestHandler.java:50) at com.inqmy.services.rfcengine.RFCJCOServer.handleRequest(RFCJCOServer.java:69) at com.sap.mw.jco.JCO$Server.dispatchRequest(Unknown Source) at com.sap.mw.jco.rfc.MiddlewareRFC$Server.nativeListen(Native Method) at com.sap.mw.jco.rfc.MiddlewareRFC$Server.listen(Unknown Source) at com.sap.mw.jco.JCO$Server.listen(Unknown Source) at com.sap.mw.jco.JCO$Server.run(Unknown Source) at java.lang.Thread.run(Thread.java:513) --
Please tell me what is the problem?
Thanks for your time
A -
Message Mapping ... ABAP ,XSLT and JAVA
HI Friends
I have a general question ... but it will confuse me a lot ....
my question is we have four types of message mappings
1) GUI ( and UDFs)
2) ABAP
3)XSLT
4) JAVA
when we have plenty of options in GUI (and User defined functions also) to define sender 2 receiver message mapping
then what is need of JAVA,ABAP and XSLT Message Mapping and when we use these message mappings( exactly in which situation) and difference b/w them
Thanks in Advance
MaheshGreen = recommended
Yellow = Acceptable
Red = not recommended
In my experience.
XSLT mapping: is confotable to convert to another format different to xml(when we do not have a complex logic)
Java Mapping: is to implement complex logics(but the maintainbilityis not good...you need a external tool)
ABAP mapping: I think is the best option when the you have the skills on that technology but take account that is not portable neither good for usability.
Regards
Ivan -
Hi,
I´m trying the "Easy RFC lookup from XSLT mappings using a Java helper class" article and I getting a weird problem.
The result of the RFC lookup called inside the java class is maintained in a kind of cache and I always get the same results independent of the parameters I use in the following calls.
Just after calling a Complete Cache Refresh (SXI_CACHE) I got a new result to the lookup.
If I call in the Interface Mapping Test option it runs fine. However, when I call it from my scenario (SOAP Adapter Sender) the first result of the lookup will be returned until a forced cache refresh.
Any ideas?
Thank you,
Fabiano.Hello Fabiano,
I had the same problem like you had.
The main Problem is that with the example code the request variable is created as NodeList object. In XSLT a variable is somekind of a constant and can't be changed. As the request object is empty after the first request the programm fails at the following line:
Source source = new DOMSource(request.item(0));
So I've created a workaround for this problem.
In the call of the template I've put the request as a parameter object at the template call:
<xsl:with-param name="req">
<rfc:PLM_EXPLORE_BILL_OF_MATERIAL xmlns:rfc="urn:sap-com:document:sap:rfc:functions">
<APPLICATION>Z001</APPLICATION>
<FLAG_NEW_EXPLOSION>X</FLAG_NEW_EXPLOSION>
<MATERIALNUMBER><xsl:value-of select="value"/></MATERIALNUMBER>
<PLANT>FSD0</PLANT>
<VALIDFROM><xsl:value-of select="//Recordset/Row[name='DTM-031']/value"/></VALIDFROM>
<BOMITEM_DATA/>
</rfc:PLM_EXPLORE_BILL_OF_MATERIAL>
</xsl:with-param>
With this change the request will be provided as a String object and not as a NodeList object.
Afterwards the RfcLookup.java has to be changed to the following:
package com.franke.mappings;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Map;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import com.sap.aii.mapping.lookup.Channel;
import com.sap.aii.mapping.api.StreamTransformationConstants;
import com.sap.aii.mapping.api.AbstractTrace;
import com.sap.aii.mapping.lookup.RfcAccessor;
import com.sap.aii.mapping.lookup.LookupService;
import com.sap.aii.mapping.lookup.XmlPayload;
* @author Thorsten Nordholm Søbirk, AppliCon A/S
* Helper class for using the XI Lookup API with XSLT mappings for calling RFCs.
* The class is generic in that it can be used to call any remote-enabled
* function module in R/3. Generation of the XML request document and parsing of
* the XML response is left to the stylesheet, where this can be done in a very
* natural manner.
* TD:
* Changed the class that request is sent as String, because of IndexOutOfBound-exception
* When sending multiple requests in one XSLT mapping.
public class RfcLookup {
* Execute RFC lookup.
* @param request RFC request - TD: changed to String
* @param service name of service
* @param channelName name of communication channel
* @param inputParam mapping parameters
* @return Node containing RFC response
public static Node execute( String request,
String service,
String channelName,
Map inputParam)
AbstractTrace trace = (AbstractTrace) inputParam.get(StreamTransformationConstants.MAPPING_TRACE);
Node responseNode = null;
try {
// Get channel and accessor
Channel channel = LookupService.getChannel(service, channelName);
RfcAccessor accessor = LookupService.getRfcAccessor(channel);
// Serialise request NodeList - TD: Not needed anymore as request is String
/*TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer();
Source source = new DOMSource(request.item(0));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
StreamResult streamResult = new StreamResult(baos);
transformer.transform(source, streamResult);*/
// TD: Add xml header and remove linefeeds for the request string
request = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"+request.replaceAll("[\r\n]+", "");
// TD: Get byte Array from request String to send afterwards
byte[] requestBytes = request.getBytes();
// TD: Not used anymore as request is String
//byte[] requestBytes = baos.toByteArray();
trace.addDebugMessage("RFC Request: " + new String(requestBytes));
// Create input stream representing the function module request message
InputStream inputStream = new ByteArrayInputStream(requestBytes);
// Create XmlPayload
XmlPayload requestPayload =LookupService.getXmlPayload(inputStream);
// Execute lookup
XmlPayload responsePayload = accessor.call(requestPayload);
InputStream responseStream = responsePayload.getContent();
TeeInputStream tee = new TeeInputStream(responseStream);
// Create DOM tree for response
DocumentBuilder docBuilder =DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document document = docBuilder.parse(tee);
trace.addDebugMessage("RFC Response: " + tee.getStringContent());
responseNode = document.getFirstChild();
} catch (Throwable t) {
StringWriter sw = new StringWriter();
t.printStackTrace(new PrintWriter(sw));
trace.addWarning(sw.toString());
return responseNode;
* Helper class which collects stream input while reading.
static class TeeInputStream extends InputStream {
private ByteArrayOutputStream baos;
private InputStream wrappedInputStream;
TeeInputStream(InputStream inputStream) {
baos = new ByteArrayOutputStream();
wrappedInputStream = inputStream;
* @return stream content as String
String getStringContent() {
return baos.toString();
/* (non-Javadoc)
* @see java.io.InputStream#read()
public int read() throws IOException {
int r = wrappedInputStream.read();
baos.write(r);
return r;
Then you need to compile and upload this class and it should work.
I hope that this helps you.
Best regards
Till -
Give me description for ABAP and XSLT and JAVA Mapping
i want detailed description for XSLT AND ABAP,JAVA Mapping and where they require coding and some examples for this items and differences for these mappings and message mapping and some examples which shows difference between these items
Hi,
Java mapping:
/people/prasad.ulagappan2/blog/2005/06/29/java-mapping-part-i
/people/prasad.ulagappan2/blog/2005/06/29/java-mapping-part-ii
ABAP Mapping:
https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/5c46ab90-0201-0010-42bd-9d0302591383
XSLT mapping
/people/anish.abraham2/blog/2005/12/22/file-to-multiple-idocs-xslt-mapping
ABAP XSLT mapping
/people/r.eijpe/blog/2005/11/04/using-abap-xslt-extensions-for-xi-mapping
Regards
Vijaya -
How to modify an XML values using XSLT and Java
Hi Friends,
I wish to modify a simple xml to another xml using XSLT, please let me know what are the things i need to know to convert the XML to another XML.
If somebody can give a sample code, it will be great...
I wish to do the following sample conversion of XML
<?xml version="1.0" encoding="ISO-8859-1" ?>
<ROOT>
<NAME>TEST1</NAME>
</ROOT>so that the results look like below....
<?xml version="1.0" encoding="ISO-8859-1" ?>
<ROOT>
<NAME>TEST2</NAME>
</ROOT>Notice TEST1 is replaced with TEST2 in the 2nd XML, I wish to get that result...please help.
Thanks and Regards,
JGThanks for your nice reply... do you have a sample code...
-
Differnce between java script xml dom and Java Xml dom
Hi,
In my application For client side in Java Script for craetion of DOM MIcrosoft Activex object is used. USing that one they are buiidng DOM. And they are saving as XML. In server side i have to write one servlet which will parse that xml and i have to store in dynamic arrays.Which API is better for parsing XML in java.In util pacakge which class is better for storing dynamical values that means MAP,Hash Map,Hash table ??in java, the java..xml.parsers package is generally used for parsing xml into a DOM. there are also sax and stax parsers available.
which class in java.util is better for storing stuff depends on what you need to do with the stuff. find a nice tutorial on java collections and then decide which one makes sense for what you need. -
XML, XSLT and Omniportlet
Hello, I hope I can find some help.
Using 10.1.14.
I'm importing an XML document. I don't know if it's in rowset/row format (don't know what that is).
I use XSL to transform it. When I click "test", I see pretty much what I want. A table tag, a td with a value, a td with another value, this repeats 4 times. This is the number of "item" elements I have. Great. Everything is set to default.
When I view my page, however, this is the response: Error fetching XML data. Or nothing, because I've tried many different configurations of XSL. When I view my page, it never works.
this is my xml:
<?xml version="1.0" encoding="UTF-8"?>
<record name="N/A" type="content">
<item name="Title"><value>Disclosure of Position Reclassifications</value></item>
<item name="Language"><value>eng</value></item>
<item name="Other Language File Name"><value>/sm/srh/prh/cngc/dsc/Reclass_f</value></item>
<item name="Content"><value>
& lt;table border="0" cellspacing="0" cellpadding="0" width="450"& gt;
& lt;tr& gt;
& lt;td colspan="3"& gt;& lt;h2& gt;Disclosure of Position Reclassifications& lt;/h2& gt;& lt;/td& gt;
& lt;/tr& gt;
& lt;/table& gt;
***LOTS OF HTML CLIPPED***
Act& lt;/u& gt;& lt;/i& gt;& lt;/a& gt; does not appear on this web site.& lt;/p& gt;
& lt;/td& gt;
& lt;/tr& gt;
& lt;/table& gt;
</value></item></record>
this is my xsl:
<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:template match="record">
<table>
<xsl:for-each select="item">
<tr>
<td><xsl:value-of select="@name"/></td>
<td><xsl:value-of select="value" disable-output-escaping="yes"/></td>
</tr>
</xsl:for-each>
</table>
</xsl:template>
</xsl:transform>Hi there,
I think missunderstand some basics.
to display XML documents, omniportlet takes in input onlu XML docs like this :
<rowset>
<row>my 1st line</row>
<row>my 2nd line</row>
<row> ... </row>
</rowset>
That means that the XML tags of your document MUST be ROWSET for the group and ROW for each element.
Omniportlet will render the previous XML fragment like this :
<table>
<tr>
<td>my 1st line</td>
<td>my 2ndline</td>
</tr>
<table>
So you got to write your XSL in order to transform your Initial XML in the rowset/row format. Omniportlet will take in charge of the HTML-table rendering.
Otherwise, your XML is not written in a good way. It should have been like this :
<?xml version="1.0" encoding="UTF-8"?>
<record name="N/A" type="content">
<Title>Disclosure of Position Reclassifications</Title>
<Language>eng</Language>
<OtherLanguageFileName>/sm/srh/prh/cngc/dsc/Reclass_f</OtherLanguageFileName>
<Content>
& lt;table border="0" cellspacing="0" cellpadding="0" width="450"& gt;
& lt;tr& gt;
& lt;td colspan="3"& gt;& lt;h2& gt;Disclosure of Position Reclassifications& lt;/h2& gt;& lt;/td& gt;
& lt;/tr& gt;
& lt;/table& gt;
***LOTS OF HTML CLIPPED***
Act& lt;/u& gt;& lt;/i& gt;& lt;/a& gt; does not appear on this web site.& lt;/p& gt;
& lt;/td& gt;
& lt;/tr& gt;
& lt;/table& gt;
</Content></record>I recommand you to have a look at XML tutorials : http://www.w3schools.com/xml/xml_elements.asp
XSL tutorials (if you need) : http://www.w3schools.com/xsl/
I hope this could help you. -
Hi all!
I'm in a bit of a dilema. As the least knowledgable member of our small development group (3 people incl. me) I'm caught in the middle of a pretty fierce debate over whether or not to we should implement JSP.
Currently to seperate business logic from presentation we have our servlets pass XML to the browser and then the browser renders the HTML using the appropriate .xsl (sometimes we use server-side transformation).
Now one of the guys wants to use MVC/Struts and JSPs in order to create a much needed UI for an application. The plan is to not put any Java code in the JSP (seperation of logic and presentation - good, business logic in both the JSP and Servlet - bad.) but the other guy is still vehemently against it.
He says that anything JSP can do we can already do with XML/XSLT and to add JSP to our environment would complicate things.
And while I agree with him there, there are some things that when you do them with JSPs make the code more readable and transparent.
If you had to take a side, which one would you choose?
Has anyone else out there already gone through this debate? I'd be interested in knowing the outcome.
Thanks,
JohnI have a couple of comments.
1> "XML to the browser and then the browser renders the HTML using the appropriate .xsl"
I all cases you should do the transformations on the server. Lot of browser do not know how to
do a xsl transform. And since you can do it some time why not do it not everytime?
2> "business logic in both the JSP and Servlet"
Business logic should neither be in servlets nor in jsp. I think they should be in business logic beans.
3> "anything JSP can do we can already do with XML/XSLT "
Although anything can be done using xml/xsl or jsp there are a bit of differences where struts-jsp architecture is more perferable.
Imaging a web site which has lots of online forms(with textfiedls, checkboxes, select lists, etc) which are to be validated and if some validation fails the same form is to be shown with the values already submitted prefilled. Doing this with xml/xsl or even simple jsp could be a nightmare.
But if you use struts MVC architecture with jsp and struts taglib this will be very very simple.
Introducing struts-jsp will not complicate things and if the scnario described above is there or could arise in your application then you should seriously think about using struts+jsp. That does not mean you will have to scrap you xml+xsl architecture. You can still generate the xml using your action bean , put the xml in request and forward it to you jsp for rendetion. The jsp page could then use a taglib which has the xsl transformation code to do the xslt transformation.
The above comments are not just my thoughts but i have also implemented/experienced the above during various projects and they have proved to be useful.
Cheers! -
Hi All,
I have an XSLT mapping program which has JAVA function in it. How should I import these files in XI repository. I tried importing zip file together and separately the XSLT and Java JAR files. When I executed the interface mapping, I am getting tons of exceptions. Could anyone please tell me the real way to succeed importing the files in repository.
Thanks
RickyHi Sandro,
I have zipped the xsl and java files in a zip file together and imported in IR.
But still its showing plenty of exceptions. Pasting the same here.
23:48:37 Start of test
com.sap.engine.services.ejb.exceptions.BaseRemoteException: Exception in method transform. at com.sap.aii.ibrep.sbeans.mapping.MapServiceRemoteObjectImpl0_0.transform(MapServiceRemoteObjectImpl0_0.java:218) at com.sap.aii.ibrep.sbeans.mapping.MapServiceRemoteObjectImpl0_0p4_Skel.dispatch(MapServiceRemoteObjectImpl0_0p4_Skel.java:104) at com.sap.engine.services.rmi_p4.DispatchImpl._runInternal(DispatchImpl.java(Compiled Code)) at com.sap.engine.services.rmi_p4.DispatchImpl._run(DispatchImpl.java(Inlined Compiled Code)) at com.sap.engine.services.rmi_p4.server.P4SessionProcessor.request(P4SessionProcessor.java(Compiled Code)) at com.sap.engine.core.service630.context.cluster.session.ApplicationSessionMessageListener.process(ApplicationSessionMessageListener.java(Compiled Code)) at com.sap.engine.core.cluster.impl6.session.MessageRunner.run(MessageRunner.java(Compiled Code)) at com.sap.engine.core.thread.impl3.ActionObject.run(ActionObject.java(Compiled Code)) at java.security.AccessController.doPrivileged1(Native Method) at java.security.AccessController.doPrivileged(AccessController.java(Compiled Code)) at com.sap.engine.core.thread.impl3.SingleThread.execute(SingleThread.java(Compiled Code)) at com.sap.engine.core.thread.impl3.SingleThread.run(SingleThread.java(Compiled Code)) Caused by: java.lang.UnsupportedClassVersionError: DateTime (Unsupported major.minor version 49.0) at java.lang.ClassLoader.defineClass0(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java(Compiled Code)) at java.lang.ClassLoader.defineClass(ClassLoader.java:708) at com.sap.aii.ibrep.server.mapping.ibrun.RepMappingLoader.findClass(RepMappingLoader.java:175) at java.lang.ClassLoader.loadClass(ClassLoader.java(Compiled Code)) at java.lang.ClassLoader.loadClass(ClassLoader.java(Compiled Code)) at com.sap.engine.lib.xsl.xpath.JLBLibrary.<init>(JLBLibrary.java(Compiled Code)) at com.sap.engine.lib.xsl.xpath.LibraryManager.getFunction(LibraryManager.java(Compiled Code)) at com.sap.engine.lib.xsl.xpath.ETFunction.evaluate(ETFunction.java(Compiled Code)) at com.sap.engine.lib.xsl.xpath.XPathProcessor.innerProcess(XPathProcessor.java(Inlined Compiled Code)) at com.sap.engine.lib.xsl.xpath.XPathProcessor.process(XPathProcessor.java(Inlined Compiled Code)) at com.sap.engine.lib.xsl.xpath.XPathProcessor.process(XPathProcessor.java(Inlined Compiled Code)) at com.sap.engine.lib.xsl.xslt.XSLValueOf.process(XSLValueOf.java(Compiled Code)) at com.sap.engine.lib.xsl.xslt.XSLNode.processFromFirst(XSLNode.java(Compiled Code)) at com.sap.engine.lib.xsl.xslt.XSLElement.process(XSLElement.java:248) at com.sap.engine.lib.xsl.xslt.XSLNode.processFromFirst(XSLNode.java(Compiled Code)) at com.sap.engine.lib.xsl.xslt.XSLElement.process(XSLElement.java:248) at com.sap.engine.lib.xsl.xslt.XSLNode.processFromFirst(XSLNode.java(Compiled Code)) at com.sap.engine.lib.xsl.xslt.XSLTemplate.process(XSLTemplate.java(Compiled Code)) at com.sap.engine.lib.xsl.xslt.XSLStylesheet.process(XSLStylesheet.java(Compiled Code)) at com.sap.engine.lib.xsl.xslt.XSLStylesheet.process(XSLStylesheet.java:431) at com.sap.engine.lib.xsl.xslt.XSLStylesheet.process(XSLStylesheet.java:394) at com.sap.engine.lib.jaxp.TransformerImpl.transformWithStylesheet(TransformerImpl.java:398) at com.sap.engine.lib.jaxp.TransformerImpl.transform(TransformerImpl.java:240) at com.sap.aii.ibrep.server.mapping.ibrun.RepMappingTransformer.transform(RepMappingTransformer.java:150) at com.sap.aii.ibrep.server.mapping.ibrun.RepXSLTMapping.execute(RepXSLTMapping.java:81) at com.sap.aii.ibrep.server.mapping.ibrun.RepMappingHandler.run(RepMappingHandler.java:80) at com.sap.aii.ibrep.server.mapping.rt.MappingHandlerAdapter.run(MappingHandlerAdapter.java:107) at com.sap.aii.ibrep.server.mapping.ServerMapService.transformInterfaceMapping(ServerMapService.java:127) at com.sap.aii.ibrep.server.mapping.ServerMapService.transform(ServerMapService.java:104) at com.sap.aii.ibrep.sbeans.mapping.MapServiceBean.transform(MapServiceBean.java:40) at com.sap.aii.ibrep.sbeans.mapping.MapServiceRemoteObjectImpl0_0.transform(MapServiceRemoteObjectImpl0_0.java:167) ... 11 more ; nested exception is: java.lang.UnsupportedClassVersionError: GetDATE_Time (Unsupported major.minor version 49.0)
23:48:38 End of test
Thanks
Ricky -
Question about Java,XSLT and XML
I am new to Java and XML. I'm not quite clear the relationship between Java,XSLT and XML.
To exercise, I am going to write a Java program that makes embedded calls to an XSLT processor(XALAN), to produce results for several constrained transformations from a given XML document(x.xml) such as:
1.Transform the x.xml (which satisfies d1.dtd) in such a way that it now conforms to the DTD d2.dtd. Output the resulting xx.xml document.
2.query some information from the x.xml and then form an Html output.
3.summary some information, do some statistics from the x.xml and then form an Html output.
I don't konw which java classes and XSLT functions might be used.(Actually I don't know how/where to start).
Can anyone give me some clue ?
thanks a lot!You must provide XSLT stylesheeds to specify transformations (1), (2),
and (3); let's call those stylesheets task1.xsl and so on.
The following code will transform x.xml into xx.xml according to task1.xsl. It gives you an idea which packages and classes to use, but it doesn't teach you proper Java programming technics :)
import java.io.File;
import javax.xml.transform.*;
import javax.xml.transform.stream.*;
public class Test
public static void main(String[] args) throws Exception
TransformerFactory factory = TransformerFactory.newInstance();
Source config = new StreamSource(new File("task1.xsl"));
Transformer transformer = factory.newTransformer(config);
Source source = new StreamSource(new File("x.xml"));
Result result = new StreamResult(new File("xx.xml"));
transformer.transform(source, result);
}To read about XSLT, see:
http://www.w3.org/TR/xslt
there is a tutorial on using XSLT with Java:
http://java.sun.com/xml/jaxp/dist/1.1/docs/tutorial/xslt/index.html. -
XML Parsing with Java - Only some attributes have start and end tags
Hello,
I am trying to interpret the XML response from a server after a HTTP request is sent to it. I have modified an example off Wikipedia below to give an example of what it looks like.
Example XML:
<Asset name="bread" prep_time="5 mins" cook_time="3 hours">
<Attribute name="Ingredient: ">Flour</Attribute>
<Attribute name="Ingredient: ">Water</Attribute>
<Attribute name="Used in Recipes:" />
</recipe>
I have been trying to display the above XML in a format such as:
name: bread prep_time: 5 mins cook_time: 3 hours
Ingredient: Flour
Ingredient: Water
Used in Recipes:
Right now I have been trying to do it manually using indexOf and substring of the XML text, but I would like to find a better way of doing this. I have found some examples online that show had to deal with cases such as
<person>
<first>Kiran</first>
<last>Pai</last>
<age>22</age>
</person>
but I do not know what to do when I encounter something like the last item, when there are no "Used in Recipe" items, and it ends with a />, instead of an ending tag </Attribute>.
Are there any suggestions as to how to handle the example XML code that I have posted?
Any help would be appreciated. Thanks.jtahlborn wrote:
Tolls wrote:
I suppose so, but since the idea is to turn it into text in a different format, XSLT strikes me as a better fit than hand crafting it.i agree if the end goal is formatted text. however, i wasn't sure if the OP was just writing some test code to figure out how to access the data or if the formatted text was the final desired output.No, true. It is open to interpretation.
jschell wrote:
(Quoting the same bit)
As long as one is mindful of the potential performance and maintenance impacts of course.Again, it depends what he's doing...true. I was making some assumptions, since (as usual) we don't really know the requirements beyond a base technical one (ie "I have this, and I need it to look like this"). In general, though, if you have XML data and you need it formatted differently then I'd say your first port of call ought to be transformation.
As for maintenance, I'd say it's easier to maintain a stylesheet than to modify Java, which is why I say it ought to be the start point.
Of course, YMMV. -
XML Parser for Java v2. Applying XSLT to DOM tree
I encountered pretty weird behavior of XML Parser for Java v2.
While applying XSLT to XML document created in memory using DOM
interface I couldn't access element attributes. For example,
given the XML document:
<root>
<Item ID="00001">Value of Item 00001</Item>
<Item ID="00002">Value of Item 00002</Item>
</root>
and XSLT:
<xsl:template match="/">
<HTML>
<HEAD>
<TITLE>XSLT Test</TITLE>
</HEAD>
<BODY>
<xsl:for-each select="/Error">
<H1>Error</H1><xsl:value-of select="."/>
</xsl:for-each>
<TABLE border="0" cellspacing="0" cellpadding="2">
<TBODY>
<xsl:for-each select="/root">
<TR>
<TH style="background-color:khaki">
<xsl:text>Attribute</xsl:text>
</TH>
<TH style="background-color:khaki">
<xsl:text>Value</xsl:text>
</TH>
</TR>
<xsl:for-each select="Item">
<TR>
<TD><xsl:value-of select="@ID"/></TD>
<TD><xsl:value-of select="."/></TD>
</TR>
</xsl:for-each>
</xsl:for-each>
</TBODY>
</TABLE>
</BODY>
</HTML>
</xsl:template>
If I build DOM tree by parsing XML file the resulting HTML
document after applying XSLT will display
Attribute Value
00001 Value of Item 00001
00002 Value of Item 00002
But if I build DOM tree using following code:
XMLDocument xDoc = new XMLDocument();
Element root = xDoc.createElement( "root" );
xDoc.appendChild( root );
Element elem = xDoc.createElement( "Item" );
elem.setAttribute( "ID", "00001" );
root.appendChild( elem ).
appendChild( xDoc.createTextNode( "Value of Item 00001" ) );
elem = xDoc.createElement( "Item" );
elem.setAttribute( "ID", "00002" );
root.appendChild( elem )
.appendChild( xDoc.createTextNode( "Value of Item 00002" ) );
the same XSLT will produce the following HTML output:
Attribute Value
Value of Item 00001
Value of Item 00002
So the value for the ID attribute is not displayed. At the same
time I can access this attribute using DOM interface. For
example, following code
NodeList nList = xDoc.getElementsByTagName( "Item" );
Element e;
for( int i = 0; i < nList.getLength(); i++ )
e = (Element)nList.item( i );
System.out.println( "ID: " + e.getAttribute( "ID" ) );
produces an output
ID: 00001
ID: 00002
Here is the code for applying XSLT to DOM tree:
DOMParser parser = new DOMParser();
parser.parse( new FileInputStream( "test.xsl" ) );
XMLDocument xsldoc = parser.getDocument();
XSLStylesheet xsl = new XSLStylesheet( xsldoc, createURL( "" ) );
XMLDocument out = new XMLDocument();
out.appendChild( new XSLProcessor().processXSL(xsl, xDoc) );
out.print( new FileOutputStream( "test.html" ) );
Andrei Filimonov
nullWe are not getting what you're getting on Solaris. See the
following:
Script started on Tue Jun 22 18:53:56 1999
Processing /view/test/vobs/oracore3/.ndeprodrc.csh
Processing /private/.nderc.csh
[test] > cat bruno.xml
<my_grandpa age="88">
<my_dad age="66">
<me age="44">
<my_son age="22">
</my_son>
</me>
</my_dad>
</my_grandpa>
[test] > cat bruno.xsl
<?xml version="1.0"?>
<!-- Identity transformation -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/XSL/Transform/1.0">
<xsl:template match="me">
<xsl:value-of select="my_son/@age"/>
<xsl:value-of select="@age"/>
<xsl:value-of select="../@age"/>
<xsl:value-of select="../../@age"/>
</xsl:template>
</xsl:stylesheet>
[test] > java XSLSample bruno.xsl bruno.xml
<root>
22446688
</root>
[test] > exit
script done on Tue Jun 22 18:54:22 1999
What platform are you on and does your stylesheet and xml doc
match ours?
Oracle XML Team
http://technet.oracle.com
Oracle Technology Network
Bruno Bontempi (guest) wrote:
: I had a similar problem in accessing element attributes from
an
: XSLT sheet.
: It seems like the processor correctly accesses element
attributes
: in the context node, but does not retrieve values of
attributes
: outside the context node.
: For example, for an XML document like:
: <my_grandpa age="88">
: <my_dad age="66">
: <me age="44">
: <my_son age="22">
: </my_son>
: </me>
: </my_dad>
: </my_grandpa>
: and an XSL stylesheet like:
: <xsl:template match="me">
: <xsl:value-of select="my_son/@age"/>
: <xsl:value-of select="@age"/>
: <xsl:value-of select="../@age"/>
: <xsl:value-of select="../../@age"/>
: </xsl:template>
: I expect an output like:
: 22446688
: but all I get is
: 44
: I am also using Jim Clark's XT, which is returning the
expected
: result.
: Thanks in advance for your help,
: Bruno.
: Andrei Filimonov (guest) wrote:
: : I encountered pretty weird behavior of XML Parser for Java
v2.
: : While applying XSLT to XML document created in memory using
DOM
: : interface I couldn't access element attributes. For example,
: : given the XML document:
: : <root>
: : <Item ID="00001">Value of Item 00001</Item>
: : <Item ID="00002">Value of Item 00002</Item>
: : </root>
: : and XSLT:
: : <xsl:template match="/">
: : <HTML>
: : <HEAD>
: : <TITLE>XSLT Test</TITLE>
: : </HEAD>
: : <BODY>
: : <xsl:for-each select="/Error">
: : <H1>Error</H1><xsl:value-of select="."/>
: : </xsl:for-each>
: : <TABLE border="0" cellspacing="0" cellpadding="2">
: : <TBODY>
: : <xsl:for-each select="/root">
: : <TR>
: : <TH style="background-color:khaki">
: : <xsl:text>Attribute</xsl:text>
: : </TH>
: : <TH style="background-color:khaki">
: : <xsl:text>Value</xsl:text>
: : </TH>
: : </TR>
: : <xsl:for-each select="Item">
: : <TR>
: : <TD><xsl:value-of select="@ID"/></TD>
: : <TD><xsl:value-of select="."/></TD>
: : </TR>
: : </xsl:for-each>
: : </xsl:for-each>
: : </TBODY>
: : </TABLE>
: : </BODY>
: : </HTML>
: : </xsl:template>
: : If I build DOM tree by parsing XML file the resulting HTML
: : document after applying XSLT will display
: : Attribute Value
: : 00001 Value of Item 00001
: : 00002 Value of Item 00002
: : But if I build DOM tree using following code:
: : XMLDocument xDoc = new XMLDocument();
: : Element root = xDoc.createElement( "root" );
: : xDoc.appendChild( root );
: : Element elem = xDoc.createElement( "Item" );
: : elem.setAttribute( "ID", "00001" );
: : root.appendChild( elem ).
: : appendChild( xDoc.createTextNode( "Value of Item
00001" )
: : elem = xDoc.createElement( "Item" );
: : elem.setAttribute( "ID", "00002" );
: : root.appendChild( elem )
: : .appendChild( xDoc.createTextNode( "Value of Item
00002" )
: : the same XSLT will produce the following HTML output:
: : Attribute Value
: : Value of Item 00001
: : Value of Item 00002
: : So the value for the ID attribute is not displayed. At the
same
: : time I can access this attribute using DOM interface. For
: : example, following code
: : NodeList nList = xDoc.getElementsByTagName( "Item" );
: : Element e;
: : for( int i = 0; i < nList.getLength(); i++ )
: : e = (Element)nList.item( i );
: : System.out.println( "ID: " + e.getAttribute( "ID" ) );
: : produces an output
: : ID: 00001
: : ID: 00002
: : Here is the code for applying XSLT to DOM tree:
: : DOMParser parser = new DOMParser();
: : parser.parse( new FileInputStream( "test.xsl" ) );
: : XMLDocument xsldoc = parser.getDocument();
: : XSLStylesheet xsl = new XSLStylesheet( xsldoc, createURL
: : XMLDocument out = new XMLDocument();
: : out.appendChild( new XSLProcessor().processXSL(xsl, xDoc) );
: : out.print( new FileOutputStream( "test.html" ) );
: : Andrei Filimonov
null
Maybe you are looking for
-
How do I stop the Cp from advancing automatically to the next slide?
I'm using Windows NT and Adobe Captivate 4. Until now, I've been creating demos in Cp4 where the movie file just continues to the next slide automatically. Now I'm making the Cp files more interactive and would like to know how to make the movie no
-
Sales invoice with 100% discount
Hi, Can you tell me if there is a way in SAP where the system allows a ZERO value to reflect in the customer account and the reconciliation account. The scenario is, material A is sold at a price of $100 to customer. A 100% Discount is given and the
-
looking for some suggestions on how to troubleshoot my Iphone 4. It just stopped working and Itunes doesn't even recognise it being plugged in
-
Which USB / Firewire ADC to use with intel iMacs?
Specifically, I want to hook my guitar up to my intel imac - and am trying to figure out what the available hardware options are. ( specifically, which units have working intel drivers ) Thanks! Nick
-
Wireless HP Printer on Dual Band Airport Extreme Base Station
I'm looking to upgrade my router to the dual band AEBS. I'll end up with some n machines and some g machines, including a wireless HP printer. Will my n-enabled machines be able to print to the g wireless printer on the g network? Thanks, JD