I have created a xslt file which transform data thats been exported from mc access as XML.
When the data is exported in a xml format, the data is shown like this:
<StudentDetails>
<StudentNumber>0112142</StudentNumber>
<SiteCode>01</SiteCode>
</StudentDetails>
In the transform file I have coded it as the following code and the output is shown above
<StudentDetails>
<xsl:element name="StudentNumber"><xsl:value-of select="StudentNumber"/></xsl:element>
<xsl:element name="SiteCode"><xsl:value-of select="SiteCode"/></xsl:element>
</StudentDetails>
However I want the output to show like this:
<StudentDetails>
<StudentNumber extension="0112142"/>
<SiteCode extension="01"/>
</StudentDetails>
How do i change my transoform code to output the data like the one shown above?
Assuming you are in the context of StudentDetails, you could do:
<StudentDetails>
<StudentNumber extension="{StudentNumber}"/>
<SiteCode extension="{SiteCode}"/>
</StudentDetails>
Read about Attribute Value Templates to understand how this works.
Related
Im looking for a possiblity to change a data structure to a other data structure.
The user should be able to define a "Input Data Template" and an "Output Data Template".
The template for the input contains an example of the expected incoming data. The user can also define variables which he can use in the output template to transfer the data.
Thats the task here is an example:
InputTemplate
<root>
<node>%data%</node>
</root>
OutputTemplate
{
"data":%data%"
}
The Input and the output can be any format a user design in his file. The main idea is to fill the variables to reuse them.
Anybody have ideas so solve this task?
Thanks for your help!
Best regards
My SOR application is returning result set, I'm performing below binary-encode and decode to retrieve json
<xsl:variable name="response_json">
<xsl:copy-of select="dp:decode(dp:binary-encode($resp/result/binary/node()), 'base-64')"/>
</xsl:varibale>
response_json - {"code":"00", "description":"Success"}.
Now how do we parse through above response_json and assign "code"/"description" values to xsl:variables and context variables using XSLTs
You have two options, IMO one good and one bad...
Let's start with the bad one which you are already on as you are using XSLT for JSON data.
Even worse option is of course to use the JSON as text only and check for the value of code and description using XSLT String functions, otherwise you need to transform the JSON data into JSONx that can be handled in XSLT by using a convert of Query Params to XML.
To do this you need to pass your JSON to a new Action (Convert QP) and then into a new Transform.
You can then use DP's JSONx to handle any "JSON" data operations you'd like as XML in the XSLT stylesheet and when done call store://jsonx2json.xsl in a new Transform to transform it into "real" JSON.
I assume you are using a dp:url-open() as you get your response in a variable but if your service has Request/Resoonse as JSON the context VAR __JSONASJSONX will automatically hold a JSONx object for you that you can use as the INPUT to any XSLT Transform action.
That being said, let's move over to the good solution; use GWS!
GWS is added to DataPower to handle JSON (and anything other than XML) and you can call a GWS from your XSLT using dp:gatewayscript() as well. See this sample: https://github.com/ibm-datapower/datapower-samples/blob/master/gatewayscript/example-ext-func-dp-gwscript.xsl
If your Transform is not doing anything XML specific I'd rewrite it into GWS!
I'm able to successfully generate JSON file from Maximo however I would like to modify the JSON before it gets generated. Like below is the sample JSON that gets generated in Maximo,
{"lastreadingdate":"2020-01-30T16:48:33+01:00",
"linearassetmeterid":0,
"sinceinstall":0.0,
"lastreading":"1,150",
"plustinitrdng":0.0,
"sincelastinspect":0.0,
"_rowstamp":"568349195",
"assetnum":"RS100003",
"active":true,
"assetmeterid":85,
"lifetodate":0.0,
"measureunitid":"KWH",
"metername":"1010",
"remarks":"TESTING JSON"}
I need the JSON to be generated as below ,
{"spi:action": "OSLC draft",
"spi:tri1readingdate":"2020-01-30T16:48:33+01:00",
"spi:tryassetmeterid":0,
"spi:install":0.0,
"spi:lastreadingTx":"1,150",
"spi:intrdngtrX":0.0,
and so on...}
Basically I need to change the target attribute names and prefix "spi" Below is the error occuring in JSON Mapping .
You're not specifying how you generate the JSON file but I'll quickly explain how you can achieve this:
As Dex pointed out, there is a JSON Mapping app in the integration module that you can use to map your outbound object structure's fields to your target structure naming.
You define your JSON structure on the JSON Mapping tab by providing a JSON sample.
You then define your mapping with Maximo on the Properties tab, like this:
Reading this IBM doc before jumping right into it should help you a lot:
https://www.ibm.com/developerworks/community/wikis/form/anonymous/api/wiki/02db2a84-fc66-4667-b760-54e495526ec1/page/e10f6e96-435d-433c-8259-5690eb756779/attachment/169224c7-10a5-4cee-af72-697a476f8b2e/media/JSON
I'm trying to write a pretty simple XML file stored in HDFS to HBase. I'd like to transform the XML file into json format and create one row in HBase for each element within the json array. See following the XML structure:
<?xml version="1.0" encoding="UTF-8"?>
<customers>
<customer customerid="1" name="John Doe"></customer>
<customer customerid="2" name="Tommy Mels"></customer>
</customers>
And see following the desired HBase output rows:
1 {"customerid"="1","name"="John Doe"}
2 {"customerid"="2","name"="Tommy Mels"}
I've tried out many different processors for my flow but this is what I've got now: GetHDFS -> ConvertRecord -> SplitJson -> PutHBaseCell. The ConvertRecord is working fine and is converting the XML file to json format properly but I can't manage to split the json records into 2. See following what I've managed to write in HBase so far (with a different processors combination):
c5927a55-d217-4dc1-af04-0aff743 column=person:rowkey, timestamp=1574329272237, value={"customerid":"1","name":"John Doe"}\x0A{
cfe4e "customerid":"2","name":"Tommy Mels"}
For the splitjson processor I'm using the following jsonpathexpression: $.*
As of now, I'm getting an IllegalArgumentException in the PutHBaseCell processor stating that the Row length is 0, see following the PutHBaseCell processor settings:
Any hints?
I think the issue is that SplitJson isn't working properly since technically the content of your flow file is multiple json documents, with one per-line. I think SplitJson would expect them to be inside an array like:
[
{"customerid"="1","name"="John Doe"},
{"customerid"="2","name"="Tommy Mels"}
]
One option is to use SplitRecord with a JsonTreeReader which should be able to understand the json-per-line format.
Another option is to avoid splitting all together and go from ConvertRecord -> PutHBaseRecord with a JsonTreeReader.
Is there a standard way to transform an input XML document with structure (scheme) of my choice to an output JSON object with structure (scheme) of my choice?
If it were transformation from input XML to output XML, I would use XSLT.
I can image the following three approaches:
Direct transformation from XML to JSON, i.e. a way to describe transformation XML -> JSON just like XSLT describes transformation XML -> XML.
I am aware of JSONML. It is a lossless JSON representation of arbitrary XML document. However, the resulting JSON object does not have the structure of my choice. If there were some standard way to describe transformation JSON -> JSON, I would chain XML -> JSONML and JSONML -> JSON.
If there were the opposite to JSONML (let's call it "XMLSON", i.e. a lossless XML notation of arbitrary JSON object), I would chain XML -> XMLSON (via XSLT) and XMLSON -> JSON.
All the three options have some "if there were". I wonder if there really is some technology to achieve the goal.
Thanks.
XSLT 3 has support to transform any XML to an XML representation of JSON defined in https://www.w3.org/TR/xslt-30/#schema-for-json and then allows you to use https://www.w3.org/TR/xslt-30/#func-xml-to-json to convert that particular XML to JSON.
The output of XSLT does not need to be XML, so if you are comfortable using that, you can go ahead and use it to output JSON.
A quick search showed up this, which might be a good example for you to start from: https://github.com/bramstein/xsltjson
It defines an XSLT function which takes an XML tree as input, and generates a string as output. Looking into the source, the basic approach is to generate an XML tree with nodes for each JSON object, array, and value, and then apply templates to that which output the JSON syntax itself.
For instance, to output a JSON array, it first generates an XML node of <json:array>...</json:array>, and then applies this template:
<xsl:template match="json:array" mode="json">
<xsl:variable name="values">
<xsl:apply-templates mode="json"/>
</xsl:variable>
<xsl:text/>[<xsl:text/>
<xsl:value-of select="string-join($values/value,',')"/>
<xsl:text/>]<xsl:text/>
</xsl:template>