Splitting xml message using XSLT
Hi,
I have XML message that I want to split up using XSLT. Following is the structure of the XML message.
<Meters>
<Meter>
<ID>1</ID>
<Type>A</Type>
<Reading ref="1A" />
</Meter>
<Meter>
<ID>2</ID>
<Type>A</Type>
<Reading ref="2A" />
</Meter>
<Meter>
<ID>3</ID>
<Type>B</Type>
<Reading ref="3B" />
</Meter>
<Reading>
<refLink>1A</refLink>
<quantity>Watts</quantity>
<value>221.00</value>
</Reading>
<Reading>
<refLink>2A</refLink>
<quantity>Wh d</quantity>
<value>0.00</value>
</Reading>
<Reading>
<refLink>3B</refLink>
<quantity>Wh r</quantity>
<value>3.00</value>
</Reading>
</Meters>
The split up should happen on the <Meter> tag. Currently, this message has three <Meter> elements. The output should result in 3 different XML messages each having its own <Meter> element. Also, please note that each <Meter> has <Reading> which is linked to the actual <Reading> data using "ref" attribute and "refLink". The value of "ref" attribute will be unique through out the XML message.
Expected output: 1.xml
<Meters>
<Meter>
<ID>1</ID>
<Type>A</Type>
<Reading ref="1A" />
</Meter>
<Reading>
<refLink>1A</refLink>
<quantity>Watts</quantity>
<value>221.00</value>
</Reading>
</Meters>
and similarly 2 more XMLs.
Please let me know if anyone has done this kind of work in XSLT.
You are right I see that xsl:document is in 1.1 recommendation, but was referred by
XSLT books I have.
I found one site that's explaining this
http://www.vbxml.com/xsl/elmxsl_document.asp
http://www.w3.org/TR/xslt11/#multiple-output
I am almost trying now to reverting to using java.util.regex and doing the split
brutforce.. :))))
- Ravi
Similar Messages
-
How to update XML file using XSLT
Hi there,
I have a "small" issue with exporting data to an XML file using XSLT.
A two steps process is needed to import data from a non-hierarchical XML file into ABAP, change the data, and then update the XML file with new values. The problem is not trivial, since the format of the XML file is a complex one: there are many interdependent elements on the same level, pointing to each other by using id and ref attributes. Based on these values the data can be read and written into an internal table. I use XSLT and XPath for that. So the inbound process is done and seems to work correctly. I have to mention that the file contains much more data than I need. I am working only with a small part of it.
Now the changed data must be exported back into the XML file, meaning that the content of certain elements must be updated. How can this be done with XSLT? I can pass only the internal table to the transformation, so how do I access the XML file in order to update it? I have tried to use the <B>xsl:document()</B> function to access the content of the file store locally on my PC, but it fails each time by throwing and URI exception. I have tried the absolute path without any addition and the path with the file:/// addition. Same result. Please advise.
Many thanks,
Ferenc
P.S. Please provide me with links only if they are relevant for this very matter. I will not give points for irrelevant postings...Now the changed data must be exported back into the XML file, meaning that the content of certain elements must be updated. How can this be done with XSLT?
XSLT approach: check these online tutorial
http://www.xml.com/pub/a/2000/08/02/xslt/index.html
http://www.xml.com/pub/a/2000/06/07/transforming/index.html
ABAP approach:
for example you have the xml (original) in a string called say xml_out .
data: l_xml type ref to cl_xml_document ,
node type ref to if_ixml_node .
create object l_xml.
call method l_xml->parse_string
exporting
stream = xml_out.
node = l_xml->find_node(
name = 'IDENTITY'
ROOT = ROOT
l_xml->set_attribute(
name = 'Name'
value = 'Charles'
node = node
(the above example reads the element IDENTITY and sets attribute name/value to the same)
like wise you can add new elements starting from IDENTITY using various methods available in class CL_XML_DOCUMENT
so how do I access the XML file in order to update it?
you have already read this XML into a ABAP variable right?
Sorry couldnt understand your whole process, why do you need to read local XML file?
Raja -
Xml messaging using jms code please
hello friends
presently i want to know how to send xml messaging using jms ..please
give me answers in simple words. please give me codeXML messages are text, so use a TextMessage. The JMS API Spec even notes that XML was a primary reason for having a TextMessage (They foresaw that XML "likely become popular").
-
Retrieving a message using XSLT
Hi,
I have XML file like the following
<doc xmlns="http://schemas.soap.org/...."
xmlns:ems="http://www.dummy.com/ems"
xmlns:op="http://www.dummy.com/ems"
>
<Message>Hello<Message>
</doc>
Now using XSLT I want to extract the message 'Hello' from Message tag.
The XSLT is
<xsl:template match="doc">
<xsl:value-of select="Message">
</xsl:template>
This XSLT is not returning me the message Hello. Had the XML been like
<doc>
<Message>Hello<Message>
</doc>
then this XSLT works fine.
Can somebody please help me get the message??
Thanks
PrashantXML should be well formed.
1.)In your XML document <Message>Hello<Message>,that is a serious error.
I suggest you close the tag <Message>
2.)In your XSLT, similar error :<xsl:value-of select="Message">
I suggest u close that as well and change it to
<xsl:value-of select="Message"/>. (Notice the " /" at the end of the tag.
It works for me..i see no reason why it shouldnt work for u after u have introduced these changes -
How to add a textline to an xml structure using xslt
Hi,
I am having a requirement where i need to add a textline to an xml.
scenario: IDOC-File and output format is an xml.
Output should be like this:
&&##AOC0MB000#AD15543390#BOIFCO#Z
<?xml version="1.0" encoding="ISO-8859-1"?>
<messages>
<batch>0800062844</batch>
<message>
<type>VPR</type>
<action>A</action>
</body>
</message>
</messages>
The line that has been added to xml is the data that will be coming from IDOC. How can we append the textline to the xml using xslt.Will document() in xslt works for doing this?The required format in ur scenario is not an xml format, so u should not save the file in xml format. U may write an adapter module at receiver to achieve this.
How can we append the textline to the xml using xslt
This is not possible as the output of xsl transformation is an xml file.
Regards,
Prateek -
String to XML conversion using XSLT
Hi all,
I have a scenario when my source input XML is in the form of a string which needs to be transformed into an XML target fields.
I am using XSLT mapping to do that and its working but unfortunately, input XML contain xml declaration <?xml version='1.0'?>. Because of which it fails.
I need to remove this. Can any body please suggest how to do this?
Any help will be appriciated.
Regards
-KulwantHi,
Refer these links
XI/PI: Convert Flat File to Deeply Nested XML Structures Using Only Graphical Mapping
Regards,
Surya -
XML transformation using XSLT in JSP page
Hi,
Please help, I'm getting this error when I try to render my xml file using an xsl style sheet in my JSP page. Am I missing a JAR? Thanks
Error 500: org/apache/xalan/xslt/XSLTInputSource
Here's xsl file
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method='html' version='1.0' encoding='UTF-8' indent='yes'/>
<xsl:template match="/">
<html>
<body>
<h2>My CD Collection</h2>
<table border="1">
<tr>
<th align="left">Title</th>
<th align="left">Artist</th>
</tr>
<xsl:for-each select="catalog/cd">
<tr>
<td><xsl:value-of select="title"/></td>
<td><xsl:value-of select="artist"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
And here's my JSP page
<%@taglib uri="http://jakarta.apache.org/taglibs/xsl-1.0" prefix="xsl"%>
<html>
<head><title>Phone Book</title></head>
<body>
<xsl:apply xml="/xml/book.xml" xsl="/xml/book.xsl" />
</body>
</html>
And here's my xml file
<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Edited with XML Spy v4.2 -->
<catalog>
<cd>
<title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
<country>USA</country>
<company>Columbia</company>
<price>10.90</price>
<year>1985</year>
</cd>
<cd>
<title>Hide your heart</title>
<artist>Bonnie Tyler</artist>
<country>UK</country>
<company>CBS Records</company>
<price>9.90</price>
<year>1988</year>
</cd>
</catalog>i would think the browser should be able do the transformation itself, rather than having to do this transformation on the server.
If you want to do this on the server, you can always try adding xalan.jar, xml-apis.jar and xercesImpl.jar to your server's lib directory, downloaded from
apache.org -
Hi,
I have a scenario where I need to perform an XML to XML transformation and I need to do this using XSLT mapping.
I am using XMLSpy.
Could somebody help me on this issue?Any weblogs that can help me on this?
regards,
PrashanthHi Prashanth,
You can do the xsl transformation in XMLSpy itself.First create your source xml file in XMLSpy by selecting file type as xml.After that create your xslt program file by selecting file type as xslt.
Then you can use the xslt program for transformation of source xml into target xml by choosing menu XSL/XQuery->XSL Transformation.
sample xsl code for an example:
source xml structure:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<header>
<detail>
Detail1
</detail>
<detail>
Detail2
</detail>
</header>
<header>
<detail>
Detail3
</detail>
</header>
</root>
xsl program:
<xsl:stylesheet version = '1.0'
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:template match="/">
<root>
<xsl:for-each select="//header">
<idoc>
<xsl:for-each select="detail">
<detail>
<xsl:value-of select="."/>
</detail>
</xsl:for-each>
</idoc>
</xsl:for-each>
</root>
</xsl:template>
</xsl:stylesheet>
target xml structure:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<idoc>
<detail>
Detail1
</detail>
<detail>
Detail2
</detail>
</idoc>
<idoc>
<detail>
Detail3
</detail>
</idoc>
</root>
Hope this would help.
Rgds
Sudhakar. -
How to Convert the following XML? using XSLT Mapper?
Hey all,
I have a simple looking but complex problem
I have a XML file like this
<userdata>
<city> new york</city>
<address>San Fransico </address>
</userdata>
My result XML should look like this
<UserDetails>
<Details>
<id>1234</id>
<place>new york</place>
</Details>
<Details>
<id>42345</id>
<place>San Fransico </place>
</Details>
</UserDetails>
I tried things but they never worked.
Any help regarding this will be of great helpppppppppppppppppppppppppp!!
Thanks in advance
-Murthy.You can use XSLT. Between, where do you want to get the ID values of the place tag in result xml.
--Shiv -
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...
-
How to use OAF transform sotred xml documents using XSLT...
Does anyone have any experience using XSLT in OAF? Specifically, I have xml documents stored in a clob to which I wish to apply an XSLT transformation and then store the transformed documents back into the clob. Is there a way to apply an XSLT transformation using say BI-Publisher via OAF?
"XML DIFF" are the keywords you can use to search for products that do this. Last time I looked there was a lot of XML Diff implementations, but none of them produced human-readable output that I really liked. I expect that's because XML diff is an easy thing for people to ask for but not an easy thing to do, given the considerable number of ways there are to change a document.
-
How To split large message using File Adapter
Hello everyone,
Here is my scenario FTP > XI > BI.
I got 2 questions:
(1) I am getting large message around 70 MB file.
How we can split the message into multiple files 10 MB each before processing the file into XI?
(2) Is there is any way we can find out size of file which is on FTP without contacting FTP admin?
through XI before processing the file?
Thanks
Vickhi vick,
check the blog
Zip or Unzip your Payload with the new PayloadZipBean module of the XI Adapter Framework
Working with the PayloadZipBean module of the XI Adapter Framework
SAP XI acting as a (huge) file mover
The specified item was not found.
Managing bulky flat messages with SAP XI (tunneling once again) - UPDATED
The specified item was not found.
regards
kummari -
XML transformation using XSLT and Resin 2.1.11
I have the following problem:
I'm using a servlet to transform the xml files in my web-app to html. The servlet caches the ones transformed results. For each request it checks if there exists a cached result and if the result is based on the most actual xml file version (checking the "lastModified" method of java.io.File that represents the requested file).
This servlet works fine and without any errors.
My web-app also has some other servlets that use the xml transformation to generate a fragment of html code (the menu structure of my "normal" servlets is defined in one xml file for all other files and servlets).
After invoking these servlets (those that use the xml transformation to create their menu) the first described servlet (transformation of requested xml files) is not working "fine" any longer. All it results is the generated header and footer of the page (hard-coded in the XSL file). The complete content is lost.
Any ideas how to solve this problem?
Thanks in advance,
Thof1. The cache:
The Hashtable is a field of my servlet called XMLTransformerServlet. The cache is not removed or deleted and none of its items is removed or deleted.
As I said: Caching works fine, wonderful, perfectly...
That's definitively not the problem.
2. Thread safety:
I've made all my servlet methods thread safe (just checked this...)
3. About the "anonymous" other servlet type that uses xml transformations:
Some of my servlets use a (thread safe) method to generate a fragment of html code that will show a simple menu structure. Therefore my web-app uses a file called menu.xml - by that way there's only one menu to maintain what makes sure that all my pages get the same menu structure (finally also the xsl file I'm using for "normal" xml transformation imports/includes and interprets this menu.xml).
The (thread safe) method has transforms the menu.xml file using a special xsl file (menu.xsl) and outputs the result to a StringWriter. From this StringWriter I obtain the code-fragment that will be returned by the method.
Before I saw the class StringWriter the first time I've used a temporary file to output the transformation result. Next I red in the file and returned its content.
Finally - this method is working fine and it's always returning the expected data.
4. The problem:
Sorry for repeating this all the time...
What I'm processing:
 - requesting some xml files -> XMLTransformerServlet is invoked and works fine:
   -> doGet checks the resource (if resource doesn't exist HTTP404 will be responded)
   -> doGet checks the caching state for this resource
      a) resource is in cache and no newer version of the File exists -> return cached element
      b) resource is in cache but a newer version exists in the file system -> recache and return newly cached element
      c) resource is not in cache -> cache the resource and return the newly cached element
 - requesting one of the other servlets (those that use xml transformation for menu generation)
   -> servlets invoked work fine
 - requesting a xml file:
   a) current version in cache -> return cached element
   b) no current version in cache -> transform the xml file and cache it
This last transformation of the requested xml file fails.
It is not failing in the sense of "throwing an exception"... it seems to work 100% fine and results a String that could be responded to the browser.
But stupidly it is not working fine...
Maybe (as you wrote) this is a bug (maybe in Resins xml transformation api).
Just thought someone else might have made a similar experience... -
Need to remove first UsernameToken header on XML document using XSLT
Can someone help me with an XSLT transformation where i want to remove the first wsse:Security header from my request message. I am not an XSLT expert, so i started playing around with XSLT code but no luck yet.
My input message Before transformation
<soapenv:Envelope xmlns:acc="http://wsdl/AccountManagerDocLiteralWrapped/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header>
<wsse:Security soapenv:actor="actor1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:UsernameToken wsu:Id="UsernameToken-1436F53E829718B6F31400871123845250">
<wsse:Username>user1</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">password</wsse:Password>
<wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">TAOptcRrjG0vM85BrdbhPw==</wsse:Nonce>
<wsu:Created>2014-05-23T18:52:03.845Z</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>
<wsse:Security soapenv:actor="actor2" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:UsernameToken wsu:Id="UsernameToken-1436F53E829718B6F31400871123845250">
<wsse:Username>user2</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">password</wsse:Password>
<wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">TAOptcRrjG0vM85BrdbhPw==</wsse:Nonce>
<wsu:Created>2014-05-23T18:52:03.845Z</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
<soapenv:Body>
<acc:transfer>
<acc:acctFrom>AC1</acc:acctFrom>
<acc:acctTo>AC2</acc:acctTo>
<acc:amount>9</acc:amount>
</acc:transfer>
</soapenv:Body>
</soapenv:Envelope>
Expected Output after Transformation
<soapenv:Envelope xmlns:acc="http://wsdl/AccountManagerDocLiteralWrapped/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header>
<wsse:Security soapenv:actor="actor2" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:UsernameToken wsu:Id="UsernameToken-1436F53E829718B6F31400871123845250">
<wsse:Username>user2</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">password</wsse:Password>
<wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">TAOptcRrjG0vM85BrdbhPw==</wsse:Nonce>
<wsu:Created>2014-05-23T18:52:03.845Z</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
<soapenv:Body>
<acc:transfer>
<acc:acctFrom>AC1</acc:acctFrom>
<acc:acctTo>AC2</acc:acctTo>
<acc:amount>9</acc:amount>
</acc:transfer>
</soapenv:Body>
</soapenv:Envelope>
Appreciate any help with this.
- dkHi Deepthi,
Please give the following snippet a try, it should ignore the first occurence of wsse:Security for the output (the first template is used to copy everything into the output, the second template is overruling the first template for the first occurence of wsse:Security and creates an empty output for it):
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<xsl:output omit-xml-declaration="yes"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="wsse:Security[1]"/>
</xsl:stylesheet> -
Open XML and using xslt with JavaScript
Hello,
I want the user to be able to choose an XML-file. This XML-file should not be placed in InDesign, there is not even a document needed for my script. All I need is a variable, containing the file. However, the XML-file should be transformed with xslt into another XML-file. How do I do this?
This is how I open the first XML-file, the one that should be transformed:
var xmlDoc = File.openDialog ("Choose XML");
if (xmlDoc == null) {return;}
xmlDoc.open("r");
xmlDoc = xmlDoc.read();
xmlDoc = new XML(xmlDoc);
I can adress different nodes and use xmlDoc as an XML-file, so that's fine, but how do I transform it?
I read the Scripting Guide and tried this:
var myDocument = app.documents.add();
var myXMLImportPreferences = app.xmlImportPreferences;
myXMLImportPreferences.transformFilename = "c:\myTransform.xsl";
var xx = myDocument.importXML(File.openDialog ("XML"));
However, it's not exactly what I want since I have to create a document and it's not working either, since xx stays undefined.
Thanks for your help.You can't get exactly what you want.
Your first code example uses the InDesign JavaScript interpreter's XML support, called E4X. It has absolutely nothing to do with the InDesign document object model or InDesign's internal support for XML. It exists only within the JavaScript interpreter. It does not support XSLT transformations.
Your second example leverages InDesign's built-in XSLT support (I'm not too sure how this works...); but that is only useful when importing XML into
InDesign, which, as you have learned, requires a document.
In the first example, you could call out to an external invokation of xsltproc and read in the input. How to do that differs for Windows and Mac.
In the second example, you could export the XML from your Document back out to an XML file and read it back in with E4X.
None of this is very appealing. What do you really need to do?
Maybe you are looking for
-
We already implemented EWA in our Solman 7.0 with DB2 Database, but when we run RTCCTOOL in SE38 in Satelite System gives error as below and Solman Component Information .. Kindly suggest do we need really required to upgrade Addonu2019s as suggested
-
Any known problems using IE6 and Adobe Reader 7 with LC:RM?
On an properly configured LC:RM server only allowing certificate (X509) authentication, Adobe Reader 7 always pops up some Username/Password dialog for authentication. Reader 8 and 9 work fine with certificates. Is this an known restriction, that Rea
-
JDEV 11 r1 Returning from page opened as dialog , give errors
I have some problems when we call pages as dialogs. When I return from dialog i have strange validation errors (Too many objects match the primary key oracle.jbo.Key[100 ].) this happens when the same view object is used from both pages. You can see
-
The music player only shows all the album covers but doesn't play the video. Only in portait mode it plays the video in a very small window. Makes no sense at all, worked perfectly in iOS6.
-
Why the **** did apple get rid of the dark keyboard for iOS 7.1?!
Apparently Apple was going to install a dark keyboard for the iPhone, but decided to get rid of it. What the ****! Does anyone know why?