PI 7.1 XSLT and ASMA
Hi,
I want to set the file name in the File Adapter as part of an XSLT-Mapping.
The steps are as follows in the XSLT:
1. Set Filename to new filename in ASMA.
2. Check if Month = '1' on payload xml. .
If month = 1 , then copy record in xml, else next record.
But I get an error:
Execution of mapping "urn:rlp.de:budgeting/OM_FileIN_to_FileOUT_Budget_1" failed. Reason: MappingException: Mapping failed, TransformException: Transformer exception occurred when executing XSLT BudgetFileNameMap (urn:rlp.de:budgeting, -1, 24903e11-1bce-11df-97ba-ddab0a076144), javax.xml.transform.TransformerException: com.sap.engine.lib.xsl.xpath.XPathException: Illegal number of arguments or types of arguments in a call of function 'dyn:put'., XPathException: Illegal number of arguments or types of arguments in a call of function 'dyn:put'.
The XSLT:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:ns0="urn:rlp.de:test:budgeting"
xmlns:map="java:java.util.Map"
xmlns:dyn="java:com.sap.aii.mapping.api.DynamicConfiguration"
xmlns:key="java:com.sap.aii.mapping.api.DynamicConfigurationKey">
<xsl:param name="inputparam"/>
<xsl:template match="/">
<!--change asma attributes -->
<xsl:variable name="dynamic-conf" select="map:get($inputparam, 'DynamicConfiguration')" />
<!-- create asma key for FileName configuration -->
<xsl:variable name="dynamic-key" select="key:create('http://sap.com/xi/XI/System/File', 'FileName')" />
<xsl:variable name="new-value" select="yourfilename.xml" />
<xsl:variable name="fileName" select="dyn:put($dynamic-conf, $dynamic-key, $new-value)" />
<MT_FileIn_Budget>
<xsl:copy-of select="/ns0:MT_FileIn_Budget/BudgetRecord[Monat=1]"/>
</MT_FileIn_Budget>
<!-- copy payload -->
<xsl:copy-of select="." />
</xsl:template>
</xsl:stylesheet>
found it, was an error in the code:
wrong: <xsl:variable name="new-value" select="yourfilename.xml" />
right: <xsl:variable name="new-value" select=" 'yourfilename.xml' " />
double quote single quote in a row!
cheers
Holger
Similar Messages
-
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 -
Any website for XSLT AND ABAP mapping
Hi XI experts,
I am looking for any good website/Material for XSLT and ABAP Mapping with examples.
So experts if you any one of you have any clue , i would appreciate it , if you post the info here .
Regds,
Ram.Hi,
For XSLT mapping, please try to create msg types for sender and recv, import these two into XML Mapforces (This is a software which enables us to do mapping this you can download from altova mapforce site) , do mapping in that mapforce , late click on XSLT icon , one XSLT file will be c reated that file , prepare zip and late come to xi , import under imported archieves,do Interface mapping by selecting the XSLT mapping option, select imported archieve..
See below examples..
https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/01a57f0b-0501-0010-3ca9-d2ea3bb983c1
http://www.troobloo.com/tech/xslt.toc.shtml
http://www.w3schools.com/xsl/
http://www.w3.org/TR/xslt
http://help.sap.com/saphelp_nw04/helpdata/en/73/f61eea1741453eb8f794e150067930/frameset.htm
https://sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/xi/xi-code-samples/generic%20xslt%20mapping%20in%20sap%20xi%2c%20part%20i.pdf
/people/anish.abraham2/blog/2005/12/22/file-to-multiple-idocs-xslt-mapping
Required XSLT Mapping tips!
Regards
Chilla.. -
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 -
XSLT and XQuery recommendation for BPEL and OSB
Hi,
1. Why is XQuery recommeded for OSB and XSLT for BPEL. Are there any specific performance optimization reason behind this.
2. Apart from OSB and BPEL, both XSLT and XQuery has xml transformation options and creating HTML. What is the difference between these two.
Thanks in advance!you can create the graphical view of Xquery in Eclipse but not for XSLT
Xquery is much faster than XSLT in OSB.
Through XSLT however you can achieve more complex transformation.
OSB has its historic origins in BEA Aqalogic stable and so Xquery was widely used used even though XSLT is supported. It is a matter of choice(your standards in your organization,your developer skillsets,your re-usable libraries etc )
In Jdeveloper you can develop xslt in graphical mode though and attain complex transformation -
XSLT and FOP in a 1.3 environment
I've just set up a small proof of concept XSLT and FOP engine under the new JVM.
But now I have to translate that back to a 1.3 environment for implementation and production.
There were two things that I noticed. Java 5.0 = simple as hell. Java 1.3 = hunt the apache classes.
Okay, I recognise that with each step forward, Sun is likely to provide their own concrete implementations of functionality we've come to expect since the last release.
Can anyone out there give me a little advice on how to go about setting up XSLT and FOP in a 1.3 environment? I've tried importing a whole range of apache jars and still find I'm short on things like "org.apache.log.Logger".
What is the bare minimum that I need?I have a feeling that I've been wasting everybody's time...
It was not of course the FOP code that relied on 1.5 as several of you pointed out. The javax transformation packages that were imported into our environment were from the 1.5 when they should have been from the earlier release, hence the StringBuilder hang up.
Having now made sure we have the right code in the right place, gues what; it works.
Apologies for the confused and confusing nature of my posts. If it is any consolation, for whatever reason, building environments within which code should run is a personal bugbear and the one thing likely to make me throw my hands up in despair.
Thanks anyway. I'll distribute some dollars on no particular basis. -
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
-
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. -
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 -
Question about JSP, XSLT and JDOM
hi, folks. Let's say within page1.jsp, i have <jsp:include page="page2.jsp" flush="true"> On the other hand, i have a servlet helper class which queries the database, then converts the ResultSet object into a JDOM Document object. My question is i want to make the transformed output of the JDOM Document and XSLT template to be a partial content of the page2.jsp page. How can i get this done properly? I have no problem of doing the transformation, but just dont know how to concatenate the output with the rest content of page2.jsp. Hope i clearly explained the question. Any advice is greatly appreciated.
//code fragment on page2.jsp
<td valign="top" width="788">
<font size="3"><br>
<p>
//i want put the transformed results here
</p>
</font>
</td>this is a fragment of my testing program, which transform direct to response output stream. but i dont want put this bounch of java code within page2.jsp. do i some other way around to get it done?
Document myDocument = createDocument();
TransformerFactory tFactory = TransformerFactory.newInstance();
// Make the input sources for the XML and XSLT documents
org.jdom.output.DOMOutputter outputter = new org.jdom.output.DOMOutputter();
org.w3c.dom.Document domDocument = outputter.output(myDocument);
javax.xml.transform.Source xmlSource = new javax.xml.transform.dom.DOMSource(domDocument);
StreamSource xsltSource = new StreamSource(new FileInputStream("d:/tomcat/webapps/project/car.xsl"));
//Make the output result for the finished document
StreamResult xmlResult = new StreamResult(response.getOutputStream());
//StreamResult xmlResult = new StreamResult(System.out);
//Get a XSLT transformer
Transformer transformer = tFactory.newTransformer(xsltSource);
//do the transform
transformer.transform(xmlSource, xmlResult); -
XSLT and ABAP Transformation Deep Structure
Hello Everyone,
While I've read the forums and the links of a number of folks doing the same thing. I am stuck in that I cannot figure out how to populate a deep structure via XSLT. Not sure what is going wrong, but I suspect it is obvious. The simple problem is that my structure is not getting populated. It is blank. The transformation works in testing STRANS (and in Stylus Studio).
I cannot figure out what is wrong that makes the t_pexr2002 table blank. Thanks for any insight.
Greg
The simple program is:
TYPES: BEGIN OF ty_head,
sndprn TYPE string,
bgmref TYPE string,
moabetrh TYPE string,
create_date TYPE string,
settlement_date TYPE string,
no_lines TYPE string,
END OF ty_head.
TYPES: BEGIN OF ty_pricing,
moabetr TYPE string,
END OF ty_pricing.
TYPES: BEGIN OF ty_item,
docname TYPE string,
docnummr TYPE string,
pricing TYPE ty_pricing,
END OF ty_item.
TYPES: BEGIN OF ty_summary,
status_message TYPE string,
END OF ty_summary.
TYPES: BEGIN OF ty_mn,
header_data TYPE ty_head,
item_data TYPE ty_item,
summary_data TYPE ty_summary,
END OF ty_mn.
DATA: t_pexr2002 TYPE STANDARD TABLE OF ty_mn.
DATA: xml_doc TYPE REF TO cl_xml_document, xml TYPE string.
CREATE OBJECT xml_doc.
CALL METHOD xml_doc->import_from_file
EXPORTING
filename = 'C:\temp\2640273.xml'.
CALL METHOD xml_doc->render_2_string
EXPORTING
pretty_print = 'X'
IMPORTING
stream = xml.
CALL TRANSFORMATION zusl_pexr2002_v1
SOURCE XML xml
RESULT output = t_pexr2002.
Edited by: Thomas Zloch on Jun 9, 2010 6:05 PMHere is my XSLT:
Here is the transformation: Also pretty simple...
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" ... >
<xsl:strip-space elements="*"/>
<xsl:template match="/PEXR2002/IDOC">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<OUTPUT>
<HEADER_DATA>
<SNDPRN>
<xsl:value-of select="EDI_DC40/SNDPRN"/>
</SNDPRN>
<BGMREF>
<xsl:value-of select="E1IDKU1/BGMREF"/>
</BGMREF>
<MOABETRH>
<xsl:value-of select="E1IDKU5/MOABETR"/>
</MOABETRH>
<CREATE_DATE>
<xsl:value-of select="EDI_DC40/CREDAT"/>
</CREATE_DATE>
<SETTLEMENT_DATE>
<xsl:value-of select="E1EDK03/DATUM"/>
</SETTLEMENT_DATE>
<NO_LINES>
<xsl:value-of select="count(E1IDPU1)"/>
</NO_LINES>
</HEADER_DATA>
<ITEM_DATA>
<xsl:for-each select="E1IDPU1">
<DOCNAME>
<xsl:value-of select="DOCNAME"/>
</DOCNAME>
<DOCNUMMR>
<xsl:value-of select="DOCNUMMR"/>
</DOCNUMMR>
<PRICING_DATA>
<xsl:for-each select="E1IDPU5[MOAQUAL = '006']">
<MOABETR>
<xsl:value-of select="MOABETR"/>
</MOABETR>
</xsl:for-each>
</PRICING_DATA>
</xsl:for-each>
</ITEM_DATA>
<SUMMARY_DATA>
<xsl:for-each select="EDI_DS40">
<STATUS_MESSAGE>
<xsl:value-of select="STAPA1"/>
</STATUS_MESSAGE>
</xsl:for-each>
</SUMMARY_DATA>
</OUTPUT>
</asx:values>
</asx:abap>
</xsl:template>
</xsl:transform>
Edited by: Thomas Zloch on Jun 9, 2010 6:05 PM -
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 -
XSLT and XML - Splitting out address data for a single XML item?
Hi,
I am currently having to change my XSLT code for processing XML feeds from the NHS because the technolgy has been moved from SOAP-based to RESTful (both of which mean very little to me!). While most of the XML feeds display correctly I have been unable to resolve the following:
The address data seems to be located under a single item <s.addressLine> rather than <address1>, <address2> <address3> <address4> as in the previous setup. As a consequence of this I am unable to split out my address data into seperate address fields (in column 2 below). The code below ....
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:s="http://syndication.nhschoices.nhs.uk/services">
<xsl:output method="html" encoding="UTF-8"/>
<xsl:template match="/">
<table class="xslt_table">
<tr>
<th>1</th>
<th>2</th>
<th>3</th>
</tr>
<xsl:for-each select="atom:feed/atom:entry">
<tr>
<td><xsl:value-of select="atom:content/s:organisationSummary/s:name"/></td>
<td><xsl:value-of select="atom:content/s:organisationSummary/s:address"/></td>
<td><xsl:value-of select="atom:content/s:organisationSummary/s:address/s:addressLine"/></td>
</tr>
</xsl:for-each>
</table>
</xsl:template>
</xsl:stylesheet>
....generates the following result:
1
2
3
Royal Eye Infirmary
Apsley RoadPlymouthDevonPL4 6PL
Apsley Road
Mount Gould Hospital
Mount Gould RoadPlymouthDevonPL4 7QD
Mount Gould Road
Scott Hospital
Beacon Park RoadPlymouthDevonPL2 2PQ
Beacon Park Road
Peninsula NHS Treatment Centre
20 Brest RoadPlymouthDevonPL6 5XP
20 Brest Road
Derriford Hospital
Derriford RoadCrownhillPlymouthDevonPL6 8DH
Derriford Road
Nuffield Health, Plymouth Hospital
Derriford RoadPlymouthDevonPL6 8BG
Derriford Road
Plympton Hospital
Market RoadPlymouthDevonPL7 1QR
Market Road
St Barnabas Hospital
Higher Port ViewSaltashCornwallPL12 4BU
Higher Port View
Liskeard Community Hospital
Clemo RoadLiskeardCornwallPL14 3XD
Clemo Road
I would be very, very grateful for any thoughts and suggestions on what I might be able to do to resolve this.
Best wishes
SimonThanks dvohra
But in my servlet, I already have the transformer factory defined as follows
public class JDOMServlet extends HttpServlet {
private TransformerFactory tFactory = TransformerFactory.newInstance();
private ResultSet rs = null;
private StreamSource xsltSource;
private Templates template;
public void init(ServletConfig config) throws ServletException {
super.init(config);
ServletContext ctx = config.getServletContext();
try {
//Want to cache the stylesheet for future resuse
//then it doesnt have to be loaded constantly
URL xslURL = ctx.getResource("/WEB-INF/viewStudentDetails.xsl");
System.out.println(xslURL);
xsltSource = new StreamSource(new java.net.URL(xslURL.toString()).openStream());
//xsltSource = new StreamSource(ctx.getResourceAsStream("/Web-inf/viewStudentDetails.xsl"));
template = tFactory.newTemplates(xsltSource);
catch (Exception e) {
e.printStackTrace();
I think the key point is that, this transformation servlet worked fine, when all it was outputting was the xml data, styled in a table. As soon as I enter more table info, (i.e. for the banner and navigation bar), the null pointer exception pops up.
....a lost and puzzled jase....
Thanks again.
JS -
Using transform api with xslt and DOM Nodes
Hi,
when trying to transform a xml document with xslt using the javax.xml.transform api
providing an element node of a previously parsed document, I find that absolute
paths are not recognized.
The following program shows what I am basically doing (the class can be executed
on the command line providing a stylesheet and xml instance):
import java.io.*;
import org.w3c.dom.*;
import javax.xml.transform.*;
import javax.xml.transform.dom.*;
import javax.xml.transform.stream.*;
import javax.xml.parsers.*;
class Transform {
public static void main(String [] args) throws Exception {
TransformerFactory tfactory = TransformerFactory.newInstance();
Transformer transformer = tfactory.newTransformer(new StreamSource(args[0]));
DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();
DocumentBuilder parser = dfactory.newDocumentBuilder();
Document doc = parser.parse(args[1]);
Element domElem = doc.getDocumentElement();
// workaround
// StringWriter out = new StringWriter();
// Transformer id = tfactory.newTransformer();
// id.transform(new DOMSource(domElem),new StreamResult(out));
// String xml = out.toString();
// transformer.transform(new StreamSource(new StringReader(xml)), new StreamResult(System.out));
transformer.transform(new DOMSource(domElem), new StreamResult(System.out));
transformer.clearParameters();
If I use this on e.g.
xsl:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes" encoding="ISO-8859-1" method="xml"/>
<xsl:template match="/">
<xsl:value-of select="/foo/bar"/>
</xsl:template>
</xsl:stylesheet>
xml:
<foo>abc<bar>def</bar></foo>
I get
<?xml version="1.0" encoding="ISO-8859-1"?>
abcdef
instead of
<?xml version="1.0" encoding="ISO-8859-1"?>
def
I think this is due to the fact, that the transformation does not recognize
any absolutely adressed xpath correctly.
From what I read in the API docs, I think what I'm doing should be ok.
So: did I misunderstand something or is this a bug in the java libraries?
I'm using j2sdk 1.4.1_01 on i386 linux.
If I use the commented code (serializing the xml and doing the transformation
with a StreamSource, that has to be parsed again), everything's fine.
Of course it would be easier to parse the file directly in the example but in the
real program, I already have a dom tree and want to transform a part of it.
Any help appreciated.
Thanks, Moruswhy?
that's all the point of XSL: define what part of your
XML you want in your XSL templates, there is no need
to prepare a sub-DOM of your DOM.
Ok. Right. That's an alternative.
The problem remains, that there are some stylesheets originally written
for the current solution and though they should work with the whole document
as well, it's not certain.
Actually I don't know if this ever worked. I did neither write this code nor maintained the system so far.
btw. you would be faster by giving a StreamSource to
your transformation.Probably yes. But that would imply to rewrite a lot of code.
What is happening is:
there is a SOAP answser containing a xml document as the result parameter.
The SOAP answer is parsed (I guess by the soap classes already) and the
result xml is extracted. That's where the element node I'm trying to transform
stems from.
Besides, I still don't see why DOMSource takes any node if only document nodes
work.
Thanks, Morus
Maybe you are looking for
-
Help! I get a 'cannot connect to iTunes Store' message....
Every time I try to purchase an item and/or download updates from App Store for installed iPhone apps I keep getting a 'Canot connect to iTunes Sore' message. On top of that, every time I try to sign in on my iPhone, I get just about half way thru wi
-
How do I open 2 finder windows in the same location?
I have one finder window I navigate to a folder that is nested 10 levels deep I want to open another finder window in the same location How do I do this? Thanks Omar
-
Bonjour found and added my Printer... but only Pretends to Print.
Windows 7; Cannon Printer USB Connected to a 2010 Model Airport Express (Firmware has been upgraded) --Bonjour did as advertised. It helped me discover and add the right print driver to my Printer list in Windows 7. --Then the PC does a great job of
-
Why when i open itunes it just shows me the music an nothing else?
can somebody help i open itunes and the only thing it gives me is the music it wont even open the ipod
-
System.exit(0) - Avoid JVM termination
Hi, Is there any possibility to avoid JVM termination when we use system.exit(0). I have created my own SecurityManager. public class MySecurityManager extends SecurityManager {.....}, and I can able to get S.O.P at public void checkPermission(final