I try to perform a Transformation to the following XML:
<?xml version="1.0" encoding="UTF-8"?>
<A_Example>
<A_ExampleType>
<RandomData1></RandomData1>
<RandomData2></RandomData2>
<RandomData3></RandomData3>
<RandomData4></RandomData4>
<RandomData5></RandomData5>
<RandomData6></RandomData6>
</A_ExampleType>
<A_ExampleType>
<RandomData1></RandomData1>
<RandomData2></RandomData2>
<RandomData3></RandomData3>
<RandomData4></RandomData4>
<RandomData5></RandomData5>
<RandomData6></RandomData6>
</A_ExampleType>
<A_ExampleType>
<RandomData1></RandomData1>
<RandomData2></RandomData2>
<RandomData3></RandomData3>
<RandomData4></RandomData4>
<RandomData5></RandomData5>
<RandomData6></RandomData6>
<to_ExampleChild>
<A_ExampleChildType>
<RandomChildData1></RandomChildData1>
<RandomChildData2></RandomChildData2>
<RandomChildData3></RandomChildData3>
<RandomChildData4></RandomChildData4>
<RandomChildData5></RandomChildData5>
<RandomChildData6></RandomChildData6>
<to_ExampleArea>
<A_ExampleAreaType>
<RandomAreaData1></RandomAreaData1>
<RandomAreaData2></RandomAreaData2>
<RandomAreaData3></RandomAreaData3>
<RandomAreaData4></RandomAreaData4>
<RandomAreaData5></RandomAreaData5>
<RandomAreaData6></RandomAreaData6>
</A_ExampleAreaType>
</to_ExampleArea>
<RandomData1></RandomData1>
<RandomData2></RandomData2>
<RandomData3></RandomData3>
<RandomData4></RandomData4>
<RandomData5></RandomData5>
<RandomData6></RandomData6>
</A_ExampleChildType>
</to_ExampleChild>
<RandomData1></RandomData1>
<RandomData2></RandomData2>
<RandomData3></RandomData3>
<RandomData4></RandomData4>
<RandomData5></RandomData5>
<RandomData6></RandomData6>
</A_ExampleType>
<A_ExampleType>
<RandomData1></RandomData1>
<RandomData2></RandomData2>
<RandomData3></RandomData3>
<RandomData4></RandomData4>
<RandomData5></RandomData5>
<RandomData6></RandomData6>
<to_ExampleChild>
<A_ExampleChildType>
<RandomChildData1></RandomChildData1>
<RandomChildData2></RandomChildData2>
<RandomChildData3></RandomChildData3>
<RandomChildData4></RandomChildData4>
<RandomChildData5></RandomChildData5>
<RandomChildData6></RandomChildData6>
<to_ExampleArea>
<A_ExampleAreaType>
<RandomAreaData1></RandomAreaData1>
<RandomAreaData2></RandomAreaData2>
<RandomAreaData3></RandomAreaData3>
<RandomAreaData4></RandomAreaData4>
<RandomAreaData5></RandomAreaData5>
<RandomAreaData6></RandomAreaData6>
</A_ExampleAreaType>
</to_ExampleArea>
<RandomData1></RandomData1>
<RandomData2></RandomData2>
<RandomData3></RandomData3>
<RandomData4></RandomData4>
<RandomData5></RandomData5>
<RandomData6></RandomData6>
</A_ExampleChildType>
</to_ExampleChild>
<RandomData1></RandomData1>
<RandomData2></RandomData2>
<RandomData3></RandomData3>
<RandomData4></RandomData4>
<RandomData5></RandomData5>
<RandomData6></RandomData6>
</A_ExampleType>
</A_Example>
I want to achieve the following output:
<A_Example>
<A_ExampleType>
<RandomData1></RandomData1>
<RandomData2></RandomData2>
<RandomData3></RandomData3>
<RandomData4></RandomData4>
<RandomData5></RandomData5>
<RandomData6></RandomData6>
</A_ExampleType>
<A_ExampleType>
<RandomData1></RandomData1>
<RandomData2></RandomData2>
<RandomData3></RandomData3>
<RandomData4></RandomData4>
<RandomData5></RandomData5>
<RandomData6></RandomData6>
</A_ExampleType>
<A_ExampleType>
<RandomData1></RandomData1>
<RandomData2></RandomData2>
<RandomData3></RandomData3>
<RandomData4></RandomData4>
<RandomData5></RandomData5>
<RandomData6></RandomData6>
<RandomChildData1></RandomChildData1
<RandomChildData2></RandomChildData2>
<RandomChildData3></RandomChildData3>
<RandomChildData4></RandomChildData4>
<RandomChildData5></RandomChildData5>
<RandomChildData6></RandomChildData6>
<RandomAreaData1></RandomAreaData1>
<RandomAreaData2></RandomAreaData2>
<RandomAreaData3></RandomAreaData3>
<RandomAreaData4></RandomAreaData4>
<RandomAreaData5></RandomAreaData5>
<RandomAreaData6></RandomAreaData6>
<RandomData1></RandomData1>
<RandomData2></RandomData2>
<RandomData3></RandomData3>
<RandomData4></RandomData4>
<RandomData5></RandomData5>
<RandomData6></RandomData6>
<RandomData1></RandomData1>
<RandomData2></RandomData2>
<RandomData3></RandomData3>
<RandomData4></RandomData4>
<RandomData5></RandomData5>
<RandomData6></RandomData6>
</A_ExampleType>
<A_ExampleType>
<RandomData1></RandomData1>
<RandomData2></RandomData2>
<RandomData3></RandomData3>
<RandomData4></RandomData4>
<RandomData5></RandomData5>
<RandomData6></RandomData6>
<RandomChildData1></RandomChildData1>
<RandomChildData2></RandomChildData2>
<RandomChildData3></RandomChildData3>
<RandomChildData4></RandomChildData4>
<RandomChildData5></RandomChildData5>
<RandomChildData6></RandomChildData6>
<RandomAreaData1></RandomAreaData1>
<RandomAreaData2></RandomAreaData2>
<RandomAreaData3></RandomAreaData3>
<RandomAreaData4></RandomAreaData4>
<RandomAreaData5></RandomAreaData5>
<RandomAreaData6></RandomAreaData6>
<RandomData1></RandomData1>
<RandomData2></RandomData2>
<RandomData3></RandomData3>
<RandomData4></RandomData4>
<RandomData5></RandomData5>
<RandomData6></RandomData6>
<RandomData1></RandomData1>
<RandomData2></RandomData2>
<RandomData3></RandomData3>
<RandomData4></RandomData4>
<RandomData5></RandomData5>
<RandomData6></RandomData6>
</A_ExampleType>
</A_Example>
In short I want a flat structure without the nested nodes. I tried to approach with the following XSLT but didn't get very far.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/A_Example">
<test>
<xsl:for-each select="//A_ExampleType">
<hallo>
<xsl:value-of select="."></xsl:value-of>
</hallo>
</xsl:for-each>
</test>
</xsl:template>
</xsl:stylesheet>
If I run my code, I get the whole data also the Data from all nodes but without the declaration. With this I mean I get something like this.
XML before run XSLT code:
<RandomData1>Test12345</RandomData1>
XML after I run the XSLT code I only get:
Test12345
Why is this happening and how can I get the declaration back?
When you only want the 'leaf' nodes (nodes without child nodes) starting from your 2nd nesting level (A_ExampleType), I'd suggest something along the lines of:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/A_Example">
<xsl:copy>
<xsl:for-each select="A_ExampleType">
<xsl:copy>
<xsl:copy-of select="descendant::*[not(child::*)]"/>
</xsl:copy>
</xsl:for-each>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Related
I have an XML input which i have to map into a target structure
Here is the link to Fiddler: LINK
<?xml version='1.0' encoding='UTF-8'?>
<root>
<d>
<Campaign>
<CampaignId>0000000112</CampaignId>
<Name>Connected Water DMI Fail Test</Name>
<MarketingAreaId>CXXGLOBAL</MarketingAreaId>
<SegmentationObject>SAP_CONTACT_ENGAGEMENT_SIN</SegmentationObject>
<ImplementationId>ZOC_EXPORT_ACOUSTIC</ImplementationId>
</Campaign>
<PackageId>47</PackageId>
<ExecutionStartDateTime>2021-06-30T15:28:49Z</ExecutionStartDateTime>
<ExecutionRunKey>42010A0350331EDBB6B6EDEF969FD623</ExecutionRunKey>
<CampaignTargetGroupMembers>
<OutboundId>A071C1B1F437B581DC597E5116B38BED039CA864</OutboundId>
<PackageId>47</PackageId>
<ExecutionRunKey>42010A0350331EDBB6B6EDEF969FD623</ExecutionRunKey>
<TargetGroupMemberAttributeData>
<AttributeId>DA-_SAP_CF_CE_CONTACT_IA_ERP_CUST-SMTP_ADDR</AttributeId>
<Value></Value>
<EdmTypeId>Edm.String</EdmTypeId>
<OutboundId>A071C1B1F437B581DC597E5116B38BED039CA864</OutboundId>
</TargetGroupMemberAttributeData>
<TargetGroupMemberAttributeData>
<AttributeId>DA-_SAP_CF_CE_CONTACT_IA_ERP_CUST-NAME_LAST</AttributeId>
<Value>Bailey</Value>
<EdmTypeId>Edm.String</EdmTypeId>
<OutboundId>A071C1B1F437B581DC597E5116B38BED039CA864</OutboundId>
</TargetGroupMemberAttributeData>
<TargetGroupMemberAttributeData>
<AttributeId>DA-_SAP_CF_CE_CONTACT_IA_ERP_CUST-NAME_FIRST</AttributeId>
<Value>Chandler</Value>
<EdmTypeId>Edm.String</EdmTypeId>
<OutboundId>A071C1B1F437B581DC597E5116B38BED039CA864</OutboundId>
</TargetGroupMemberAttributeData>
</CampaignTargetGroupMembers>
<CampaignTargetGroupMembers>
<OutboundId>E6713D258EAC1ADACE6AC905BB3ECF5E1CEF4776</OutboundId>
<PackageId>47</PackageId>
<ExecutionRunKey>42010A0350331EDBB6B6EDEF969FD623</ExecutionRunKey>
<TargetGroupMemberAttributeData>
<AttributeId>DA-_SAP_CF_CE_CONTACT_IA_ERP_CUST-SMTP_ADDR</AttributeId>
<Value>rcgrymm#gmail.com</Value>
<EdmTypeId>Edm.String</EdmTypeId>
<OutboundId>E6713D258EAC1ADACE6AC905BB3ECF5E1CEF4776</OutboundId>
</TargetGroupMemberAttributeData>
<TargetGroupMemberAttributeData>
<AttributeId>DA-_SAP_CF_CE_CONTACT_IA_ERP_CUST-NAME_LAST</AttributeId>
<Value>Carmona</Value>
<EdmTypeId>Edm.String</EdmTypeId>
<OutboundId>E6713D258EAC1ADACE6AC905BB3ECF5E1CEF4776</OutboundId>
</TargetGroupMemberAttributeData>
<TargetGroupMemberAttributeData>
<AttributeId>DA-_SAP_CF_CE_CONTACT_IA_ERP_CUST-NAME_FIRST</AttributeId>
<Value>Ruben</Value>
<EdmTypeId>Edm.String</EdmTypeId>
<OutboundId>E6713D258EAC1ADACE6AC905BB3ECF5E1CEF4776</OutboundId>
</TargetGroupMemberAttributeData>
</CampaignTargetGroupMembers>
</d>
</root>
I have to write XSLT code so that node and subnodes only get copied and formatted with new field names when AttributeId = DA-_SAP_CF_CE_CONTACT_IA_ERP_CUST-SMTP_ADDR and corresponding Value != ''
How do i modify XSLT Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="node()|#*">
<xsl:copy>
<xsl:apply-templates select="node()|#*"/>
</xsl:copy>
</xsl:template>
<xsl:variable name="campaign" select="root/d/Campaign/CampaignId/text()" />
<xsl:template match="TargetGroupMemberAttributeData[AttributeId='DA-_SAP_CF_CE_CONTACT_IA_ERP_CUST-NAME_FIRST']">
<FIRST_NAME><xsl:value-of select="Value"/></FIRST_NAME>
</xsl:template>
<xsl:template match="TargetGroupMemberAttributeData[AttributeId='DA-_SAP_CF_CE_CONTACT_IA_ERP_CUST-NAME_LAST']">
<LAST_NAME><xsl:value-of select="Value" /></LAST_NAME>
<xsl:template match="CampaignTargetGroupMembers/ExecutionRunKey">
<CAMPAIGN_ID><xsl:copy-of select="$campaign"/></CAMPAIGN_ID>
</xsl:template>
<xsl:template match="TargetGroupMemberAttributeData[AttributeId='OUTBOUND_INTERACTION']">
<UUID><xsl:value-of select="Value" /></UUID>
</xsl:template>
</xsl:stylesheet>
The output Should be:
<?xml version="1.0" encoding="UTF-8"?><root>
<d>
<Campaign>
<CampaignId>0000000112</CampaignId>
<Name>Connected Water DMI Fail Test</Name>
<MarketingAreaId>CXXGLOBAL</MarketingAreaId>
<SegmentationObject>SAP_CONTACT_ENGAGEMENT_SIN</SegmentationObject>
<ImplementationId>ZOC_EXPORT_ACOUSTIC</ImplementationId>
</Campaign>
<PackageId>47</PackageId>
<ExecutionStartDateTime>2021-06-30T15:28:49Z</ExecutionStartDateTime>
<ExecutionRunKey>42010A0350331EDBB6B6EDEF969FD623</ExecutionRunKey>
<CampaignTargetGroupMembers>
<OutboundId>E6713D258EAC1ADACE6AC905BB3ECF5E1CEF4776</OutboundId>
<PackageId>47</PackageId>
<CAMPAIGN_ID>0000000112</CAMPAIGN_ID>
<Email>rcgrymm#gmail.com</Email>
<LAST_NAME>Carmona</LAST_NAME>
<FIRST_NAME>Ruben</FIRST_NAME>
<TargetGroupMemberAttributeData>
<AttributeId>DA-_SAP_CF_CE_CONTACT_IA_ERP_CUST-INITIATIVE_ID</AttributeId>
<Value>0000000105,0000000092,0000000041,,0000000054,0000000076</Value>
<EdmTypeId>Edm.String</EdmTypeId>
<OutboundId>E6713D258EAC1ADACE6AC905BB3ECF5E1CEF4776</OutboundId>
</TargetGroupMemberAttributeData>
</CampaignTargetGroupMembers>
</d>
</root>
To get the desired output, you can use the following stylesheet. But not all values could be derived from your source, so I put in some static values. I guess that you could fill in the rest.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:variable name="campaign" select="root/d/Campaign/CampaignId/text()" />
<xsl:mode on-no-match="shallow-copy" />
<xsl:strip-space elements="*" />
<xsl:template match="CampaignTargetGroupMembers | TargetGroupMemberAttributeData" />
<xsl:template match="CampaignTargetGroupMembers[TargetGroupMemberAttributeData[AttributeId='DA-_SAP_CF_CE_CONTACT_IA_ERP_CUST-SMTP_ADDR' and Value!='']]">
<xsl:copy>
<xsl:apply-templates select="#* | OutboundId | PackageId"/>
<CAMPAIGN_ID><xsl:value-of select="$campaign" /></CAMPAIGN_ID>
<Email><xsl:value-of select="TargetGroupMemberAttributeData[AttributeId='DA-_SAP_CF_CE_CONTACT_IA_ERP_CUST-SMTP_ADDR']/Value" /></Email>
<LAST_NAME><xsl:value-of select="TargetGroupMemberAttributeData[AttributeId='DA-_SAP_CF_CE_CONTACT_IA_ERP_CUST-NAME_LAST']/Value" /></LAST_NAME>
<FIRST_NAME><xsl:value-of select="TargetGroupMemberAttributeData[AttributeId='DA-_SAP_CF_CE_CONTACT_IA_ERP_CUST-NAME_FIRST']/Value"/></FIRST_NAME>
<TargetGroupMemberAttributeData>
<AttributeId>DA-_SAP_CF_CE_CONTACT_IA_ERP_CUST-INITIATIVE_ID</AttributeId>
<Value>0000000105,0000000092,0000000041,,0000000054,0000000076</Value>
<EdmTypeId><xsl:value-of select="TargetGroupMemberAttributeData[1]/EdmTypeId" /></EdmTypeId>
<OutboundId><xsl:value-of select="TargetGroupMemberAttributeData[1]/OutboundId" /></OutboundId>
</TargetGroupMemberAttributeData>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Its output is:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<d>
<Campaign>
<CampaignId>0000000112</CampaignId>
<Name>Connected Water DMI Fail Test</Name>
<MarketingAreaId>CXXGLOBAL</MarketingAreaId>
<SegmentationObject>SAP_CONTACT_ENGAGEMENT_SIN</SegmentationObject>
<ImplementationId>ZOC_EXPORT_ACOUSTIC</ImplementationId>
</Campaign>
<PackageId>47</PackageId>
<ExecutionStartDateTime>2021-06-30T15:28:49Z</ExecutionStartDateTime>
<ExecutionRunKey>42010A0350331EDBB6B6EDEF969FD623</ExecutionRunKey>
<CampaignTargetGroupMembers>
<OutboundId>E6713D258EAC1ADACE6AC905BB3ECF5E1CEF4776</OutboundId>
<PackageId>47</PackageId>
<CAMPAIGN_ID>0000000112</CAMPAIGN_ID>
<Email>rcgrymm#gmail.com</Email>
<LAST_NAME>Carmona</LAST_NAME>
<FIRST_NAME>Ruben</FIRST_NAME>
<TargetGroupMemberAttributeData>
<AttributeId>DA-_SAP_CF_CE_CONTACT_IA_ERP_CUST-INITIATIVE_ID</AttributeId>
<Value>0000000105,0000000092,0000000041,,0000000054,0000000076</Value>
<EdmTypeId>Edm.String</EdmTypeId>
<OutboundId>E6713D258EAC1ADACE6AC905BB3ECF5E1CEF4776</OutboundId>
</TargetGroupMemberAttributeData>
</CampaignTargetGroupMembers>
</d>
</root>
Which is as desired (with some static values which cannot be deduced from the input XML).
I have the following:
<ns0:tXML>
<Message>
<Report>
<Page>
<PageID>01</PageID>
<PageDetail>
<PageName>11</PageName>
<Totals>
<Num>10</Num>
</Totals>
</PageDetail>
<PageDetail>
<PageName>11</PageName>
<Totals>
<Num>5</Num>
</Totals>
</PageDetail>
</Page>
<Page>
<PageID>02</PageID>
<PageDetail>
<PageName>12</PageName>
<Totals>
<Num>10</Num>
</Totals>
</PageDetail>
<PageDetail>
<PageName>12</PageName>
<Totals>
<Num>3</Num>
</Totals>
</PageDetail>
</Page>
</Report>
</Message>
</ns0:tXML>
I want to make the output so that PageDetails are combined for each Page as long as their PageName and PageID are the same, including summing the values of the combined.
Output Wanted:
<ns0:tXML>
<Message>
<Report>
<Page>
<PageID>01</PageID>
<PageDetail>
<PageName>11</PageName>
<Totals>
<Num>15</Num>
</Totals>
</PageDetail>
</Page>
<Page>
<PageID>02</PageID>
<PageDetail>
<PageName>12</PageName>
<Totals>
<Num>13</Num>
</Totals>
</PageDetail>
</Page>
</Report>
</Message>
</ns0:tXML>
How would I go about it? All efforts with using keys and playing with templates has led to cases where only one of the Pages got created, or it combined all the Pages no matter where they were on the xml, showing that I was likely trying to do an all apply to it rather than sticking to the current context.
Let's start from a little correction to your source. It should include
the namespace specification:
<ns0:tXML xmlns:ns0="urn.dummy.com">
otherwise there is reported the following error:
The prefix "ns0" for element "ns0:tXML" is not bound.
One of possible solutions is to use the following script:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ns0="urn.dummy.com">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:key name="Pd" match="PageDetail" use="concat(../PageID, '|', PageName)"/>
<xsl:template match="Page">
<xsl:copy>
<xsl:copy-of select="PageID"/>
<xsl:for-each select="PageDetail[generate-id()=generate-id(key('Pd',
concat(../PageID,'|', PageName))[1])]">
<xsl:variable name="kk" select="concat(../PageID,'|', PageName)"/>
<xsl:copy>
<xsl:copy-of select="PageName"/>
<xsl:element name="Totals">
<xsl:element name="Num">
<xsl:value-of select="sum(key('Pd', $kk)/Totals/Num)"/>
</xsl:element>
</xsl:element>
</xsl:copy>
</xsl:for-each>
</xsl:copy>
</xsl:template>
<xsl:template match="#*|node()">
<xsl:copy><xsl:apply-templates select="#*|node()"/></xsl:copy>
</xsl:template>
</xsl:transform>
For a working example, generating just your expected result,
see: http://xsltransform.net/93YRmgt
I have records in database which has same order header with all lines records
Could anybody please help me how to use xsl to transform
<?xml version='1.0' encoding='UTF-8'?>
<getParentChildOutputCollection xmlns="http://xmlns.oracle.com/cloud/adapter/dbaasdatabase/getParentChild_REQUEST/types">
<getParentChildOutput>
<PID>1</PID>
<PNAME>Xerox</PNAME>
<CID>101</CID>
<CNAME>Order 101</CNAME>
<CDESC>Order Paper</CDESC>
</getParentChildOutput>
<getParentChildOutput>
<PID>1</PID>
<PNAME>Xerox</PNAME>
<CID>102</CID>
<CNAME>Order 102</CNAME>
<CDESC>Order Black Ink</CDESC>
</getParentChildOutput>
<getParentChildOutput>
<PID>1</PID>
<PNAME>Xerox</PNAME>
<CID>103</CID>
<CNAME>Order 103</CNAME>
<CDESC>Order Staple Pin</CDESC>
</getParentChildOutput>
<getParentChildOutput>
<PID>2</PID>
<PNAME>HP</PNAME>
<CID>230</CID>
<CNAME>Order 230</CNAME>
<CDESC>Order Red Ink</CDESC>
</getParentChildOutput>
<getParentChildOutput>
<PID>2</PID>
<PNAME>HP</PNAME>
<CID>231</CID>
<CNAME>Order 231</CNAME>
<CDESC>Order Blue Ink</CDESC>
</getParentChildOutput>
</getParentChildOutputCollection>
I want to transform above sml using xsl to below output
<?xml version="1.0" encoding="utf-8"?>
<request-wrapper>
<TransmissionID>1234</TransmissionID>
<DeliveryOrders>
<OrderCode>1</OrderCode>
<Company>Xerox</Company>
<Lines>
<c1d>101</c1d>
<cname>Order 101</cname>
<cdesc>Order Paper</cdesc>
</Lines>
<Lines>
<c1d>102</c1d>
<cname>Order 102</cname>
<cdesc>Order Black Ink</cdesc>
</Lines>
<Lines>
<c1d>3</c1d>
<cname>Order 103</cname>
<cdesc>Order Staple Pin</cdesc>
</Lines>
</DeliveryOrders>
<DeliveryOrders>
<OrderCode>2</OrderCode>
<Company>p2</Company>
<Lines>
<c1d>230</c1d>
<cname>Order 230</cname>
<cdesc>Order Red Ink</cdesc>
</Lines>
<Lines>
<c1d>231</c1d>
<cname>Order 231</cname>
<cdesc>Order Blue Ink</cdesc>
</Lines>
</DeliveryOrders>
</request-wrapper>
I have used the below xsl but in the application I am working it is not working, it is not recognize the key and generate-id commands. Are there any other way I can acheive this?
<?xml version = '1.0' encoding = 'UTF-8'?>
<xsl:stylesheet version="2.0" xml:id="id_1" xmlns:nssrcmpr="http://www.oracle.com/2014/03/ics/schedule" xmlns:nstrgdfl="http://xmlns.oracle.com/cloud/adapter/ftp/writejson/types" xmlns:oraext="http://www.oracle.com/XSL/Transform/java/oracle.tip.pc.services.functions.ExtFunc" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:plnk="http://schemas.xmlsoap.org/ws/2003/05/partner-link/" xmlns:xp20="http://www.oracle.com/XSL/Transform/java/oracle.tip.pc.services.functions.Xpath20" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:nstrgmpr="http://xmlns.oracle.com/cloud/adapter/ftp/writejson_REQUEST/types" xmlns:ora="http://schemas.oracle.com/xpath/extension" xmlns:oracle-xsl-mapper="http://www.oracle.com/xsl/mapper/schemas" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:ns1="http://xml.oracle.com/adapters/extension" xmlns:ns5="http://xmlns.oracle.com/cloud/adapter/ftp/writejson_REQUEST" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" exclude-result-prefixes=" nssrcmpr oraext xsd xp20 ora oracle-xsl-mapper xsi fn ns1 xsl ignore01" xmlns:ignore01="http://www.oracle.com/XSL/Transform/java" ignore01:ignorexmlids="true" xmlns:nsmpr0="http://xmlns.oracle.com/cloud/adapter/dbaasdatabase/getParentChild_REQUEST/types" xmlns:nsmpr1="http://www.oracle.com/2014/03/ic/integration/metadata" xmlns:xml="http://www.w3.org/XML/1998/namespace" xmlns:ns23="http://xmlns.oracle.com/cloud/ftp/write/response/pull" xmlns:flt="http://xmlns.oracle.com/cloud/generic/service/fault" xmlns:dvm="http://www.oracle.com/XSL/Transform/java/com.bea.wli.sb.functions.dvm.DVMFunctions" xmlns:orajs0="http://www.oracle.com/XSL/Transform/java/oracle.tip.pc.services.functions.JsExecutor_xpath1453381219" xmlns:ns22="http://xml.oracle.com/types" xmlns:orajs6="http://www.oracle.com/XSL/Transform/java/oracle.tip.pc.services.functions.JsExecutor_xpath1211296200" xmlns:orajs3="http://www.oracle.com/XSL/Transform/java/oracle.tip.pc.services.functions.JsExecutor_xpath213937888" xmlns:orajs1="http://www.oracle.com/XSL/Transform/java/oracle.tip.pc.services.functions.JsExecutor_xpath562866038" xmlns:orajs7="http://www.oracle.com/XSL/Transform/java/oracle.tip.pc.services.functions.JsExecutor_xpath86288" xmlns:tns="http://xmlns.oracle.com/cloud/adapter/dbaasdatabase/getParentChild_REQUEST" xmlns:ns2="http://www.oracle.com/XSL/Transform/java/com.bea.wli.sb.resources.icsxpathfunctions.ICSInstanceTrackingFunctions" xmlns:orajs2="http://www.oracle.com/XSL/Transform/java/oracle.tip.pc.services.functions.JsExecutor_xpath1600802978" xmlns:orajs5="http://www.oracle.com/XSL/Transform/java/oracle.tip.pc.services.functions.JsExecutor_xpath2113524327" xmlns:orajs4="http://www.oracle.com/XSL/Transform/java/oracle.tip.pc.services.functions.JsExecutor_xpath1290874520" xmlns:ns0="http://www.oracle.com/XSL/Transform/java/oracle.tip.dvm.LookupValue">
<oracle-xsl-mapper:schema xml:id="id_2">
<!--SPECIFICATION OF MAP SOURCES AND TARGETS, DO NOT MODIFY.-->
<oracle-xsl-mapper:mapSources xml:id="id_3">
<oracle-xsl-mapper:source type="XSD" xml:id="id_4">
<oracle-xsl-mapper:schema location="../../processor_13/resourcegroup_14/ICSSchedule_1.xsd" xml:id="id_5"/>
<oracle-xsl-mapper:rootElement name="schedule" namespace="http://www.oracle.com/2014/03/ics/schedule" xml:id="id_6"/>
</oracle-xsl-mapper:source>
<oracle-xsl-mapper:source type="WSDL" xml:id="id_13">
<oracle-xsl-mapper:schema location="../../application_27/inbound_28/resourcegroup_29/getParentChild_REQUEST.wsdl" xml:id="id_14"/>
<oracle-xsl-mapper:rootElement name="getParentChildOutputCollection" namespace="http://xmlns.oracle.com/cloud/adapter/dbaasdatabase/getParentChild_REQUEST/types" xml:id="id_15"/>
<oracle-xsl-mapper:param name="getParentChild" xml:id="id_16"/>
</oracle-xsl-mapper:source>
</oracle-xsl-mapper:mapSources>
<oracle-xsl-mapper:mapTargets xml:id="id_7">
<oracle-xsl-mapper:target type="WSDL" xml:id="id_8">
<oracle-xsl-mapper:schema location="../../application_49/inbound_50/resourcegroup_51/writejson_REQUEST.wsdl" xml:id="id_9"/>
<oracle-xsl-mapper:rootElement name="WriteFile" namespace="http://xmlns.oracle.com/cloud/adapter/ftp/writejson_REQUEST/types" xml:id="id_10"/>
</oracle-xsl-mapper:target>
</oracle-xsl-mapper:mapTargets>
<!--GENERATED BY ORACLE XSL MAPPER 12.1.2.0.0-->
</oracle-xsl-mapper:schema>
<!--User Editing allowed BELOW this line - DO NOT DELETE THIS LINE-->
<xsl:param name="getParentChild" xml:id="id_25"/>
<xsl:key name="keyHeader" match="nsmpr0:getParentChildOutput" use="nsmpr0:PID" />
<xsl:key name="keyLines" match="nsmpr0:getParentChildOutput" use="concat(nsmpr0:PID,'#',nsmpr0:CID)" />
<xsl:template match="/" xml:id="id_11">
<nstrgmpr:WriteFile xml:id="id_12">
<nstrgdfl:request-wrapper xml:id="id_31">
<!--<xsl:for-each xml:id="id_33" select="$getParentChild/nsmpr0:getParentChildOutputCollection/nsmpr0:getParentChildOutput">-->
<xsl:for-each xml:id="id_33" select="row[generate-id() = generate-id(key('keyHeader', nsmpr0:PID)[1])]"> <!--Sreejit 1 -->
<nstrgdfl:DeliveryOrders xml:id="id_34">
<nstrgdfl:OrderCode xml:id="id_40">
<xsl:value-of xml:id="id_41" select="nsmpr0:PID"/>
</nstrgdfl:OrderCode>
<nstrgdfl:Company xml:id="id_38">
<xsl:value-of xml:id="id_42" select="nsmpr0:PNAME"/>
</nstrgdfl:Company>
<!-- <xsl:for-each xml:id="id_36" select="."> -->
<xsl:for-each xml:id="id_36" select="key('keyHeader', nsmpr0:PID)[generate-id() = generate-id(key('keyLines', concat(nsmpr0:PID,'#',nsmpr0:CID))[1])]"> <!--Sreejit 2 -->
<nstrgdfl:Lines xml:id="id_37">
<nstrgdfl:c1d xml:id="id_43">
<xsl:value-of xml:id="id_44" select="nsmpr0:CID"/>
</nstrgdfl:c1d>
<nstrgdfl:cname xml:id="id_45">
<xsl:value-of xml:id="id_46" select="nsmpr0:CNAME"/>
</nstrgdfl:cname>
<nstrgdfl:cdesc xml:id="id_47">
<xsl:value-of xml:id="id_48" select="nsmpr0:CDESC"/>
</nstrgdfl:cdesc>
</nstrgdfl:Lines>
</xsl:for-each>
</nstrgdfl:DeliveryOrders>
</xsl:for-each>
</nstrgdfl:request-wrapper>
</nstrgmpr:WriteFile>
</xsl:template>
</xsl:stylesheet>
Regards,
Sree
Your instruction:
<xsl:for-each xml:id="id_33" select="row[generate-id() = generate-id(key('keyHeader', nsmpr0:PID)[1])]">
selects nothing because there is no element named row in the current context (or in the entire input document, for that matter).
Side note: your stylesheet is tagged version="2.0" yet you are attempting to use Muenchian grouping - which makes very little sense.
I pasted the code which worked, just for others in case anybody want the code
<?xml version='1.0' encoding='UTF-8'?>
<xsl:stylesheet version="2.0" xml:id="id_1" xmlns:nssrcmpr="http://www.oracle.com/2014/03/ics/schedule" xmlns:nstrgdfl="http://xmlns.oracle.com/cloud/adapter/ftp/writejson/types" xmlns:oraext="http://www.oracle.com/XSL/Transform/java/oracle.tip.pc.services.functions.ExtFunc" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:plnk="http://schemas.xmlsoap.org/ws/2003/05/partner-link/" xmlns:xp20="http://www.oracle.com/XSL/Transform/java/oracle.tip.pc.services.functions.Xpath20" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:nstrgmpr="http://xmlns.oracle.com/cloud/adapter/ftp/writejson_REQUEST/types" xmlns:ora="http://schemas.oracle.com/xpath/extension" xmlns:oracle-xsl-mapper="http://www.oracle.com/xsl/mapper/schemas" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:ns1="http://xml.oracle.com/adapters/extension" xmlns:ns5="http://xmlns.oracle.com/cloud/adapter/ftp/writejson_REQUEST" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" exclude-result-prefixes=" nssrcmpr oraext xsd xp20 ora oracle-xsl-mapper xsi fn ns1 xsl ignore01" xmlns:ignore01="http://www.oracle.com/XSL/Transform/java" ignore01:ignorexmlids="true" xmlns:nsmpr0="http://xmlns.oracle.com/cloud/adapter/dbaasdatabase/getParentChild_REQUEST/types" xmlns:nsmpr1="http://www.oracle.com/2014/03/ic/integration/metadata" xmlns:xml="http://www.w3.org/XML/1998/namespace" xmlns:ns23="http://xmlns.oracle.com/cloud/ftp/write/response/pull" xmlns:flt="http://xmlns.oracle.com/cloud/generic/service/fault" xmlns:dvm="http://www.oracle.com/XSL/Transform/java/com.bea.wli.sb.functions.dvm.DVMFunctions" xmlns:orajs0="http://www.oracle.com/XSL/Transform/java/oracle.tip.pc.services.functions.JsExecutor_xpath1453381219" xmlns:ns22="http://xml.oracle.com/types" xmlns:orajs6="http://www.oracle.com/XSL/Transform/java/oracle.tip.pc.services.functions.JsExecutor_xpath1211296200" xmlns:orajs3="http://www.oracle.com/XSL/Transform/java/oracle.tip.pc.services.functions.JsExecutor_xpath213937888" xmlns:orajs1="http://www.oracle.com/XSL/Transform/java/oracle.tip.pc.services.functions.JsExecutor_xpath562866038" xmlns:orajs7="http://www.oracle.com/XSL/Transform/java/oracle.tip.pc.services.functions.JsExecutor_xpath86288" xmlns:tns="http://xmlns.oracle.com/cloud/adapter/dbaasdatabase/getParentChild_REQUEST" xmlns:ns2="http://www.oracle.com/XSL/Transform/java/com.bea.wli.sb.resources.icsxpathfunctions.ICSInstanceTrackingFunctions" xmlns:orajs2="http://www.oracle.com/XSL/Transform/java/oracle.tip.pc.services.functions.JsExecutor_xpath1600802978" xmlns:orajs5="http://www.oracle.com/XSL/Transform/java/oracle.tip.pc.services.functions.JsExecutor_xpath2113524327" xmlns:orajs4="http://www.oracle.com/XSL/Transform/java/oracle.tip.pc.services.functions.JsExecutor_xpath1290874520" xmlns:ns0="http://www.oracle.com/XSL/Transform/java/oracle.tip.dvm.LookupValue">
<oracle-xsl-mapper:schema xml:id="id_2">
<!--SPECIFICATION OF MAP SOURCES AND TARGETS, DO NOT MODIFY.-->
<oracle-xsl-mapper:mapSources xml:id="id_3">
<oracle-xsl-mapper:source type="XSD" xml:id="id_4">
<oracle-xsl-mapper:schema location="../../processor_13/resourcegroup_14/ICSSchedule_1.xsd" xml:id="id_5"/>
<oracle-xsl-mapper:rootElement name="schedule" namespace="http://www.oracle.com/2014/03/ics/schedule" xml:id="id_6"/>
</oracle-xsl-mapper:source>
<oracle-xsl-mapper:source type="WSDL" xml:id="id_13">
<oracle-xsl-mapper:schema location="../../application_27/inbound_28/resourcegroup_29/getParentChild_REQUEST.wsdl" xml:id="id_14"/>
<oracle-xsl-mapper:rootElement name="getParentChildOutputCollection" namespace="http://xmlns.oracle.com/cloud/adapter/dbaasdatabase/getParentChild_REQUEST/types" xml:id="id_15"/>
<oracle-xsl-mapper:param name="getParentChild" xml:id="id_16"/>
</oracle-xsl-mapper:source>
</oracle-xsl-mapper:mapSources>
<oracle-xsl-mapper:mapTargets xml:id="id_7">
<oracle-xsl-mapper:target type="WSDL" xml:id="id_8">
<oracle-xsl-mapper:schema location="../../application_49/inbound_50/resourcegroup_51/writejson_REQUEST.wsdl" xml:id="id_9"/>
<oracle-xsl-mapper:rootElement name="WriteFile" namespace="http://xmlns.oracle.com/cloud/adapter/ftp/writejson_REQUEST/types" xml:id="id_10"/>
</oracle-xsl-mapper:target>
</oracle-xsl-mapper:mapTargets>
<!--GENERATED BY ORACLE XSL MAPPER 12.1.2.0.0-->
</oracle-xsl-mapper:schema>
<!--User Editing allowed BELOW this line - DO NOT DELETE THIS LINE-->
<xsl:param name="getParentChild" xml:id="id_25"/>
<xsl:output method="xml" version="1.0" indent="yes" omit-xml-declaration="no"/>
<xsl:template match="/" xml:id="id_11">
<nstrgmpr:WriteFile xml:id="id_12">
<nstrgdfl:request-wrapper xml:id="id_31">
<xsl:for-each-group xml:id="id_33" select="$getParentChild/nsmpr0:getParentChildOutputCollection/nsmpr0:getParentChildOutput" group-by="nsmpr0:PID">
<nstrgdfl:DeliveryOrders xml:id="id_34">
<nstrgdfl:OrderCode xml:id="id_40">
<xsl:value-of xml:id="id_41" select="nsmpr0:PID"/>
</nstrgdfl:OrderCode>
<nstrgdfl:Company xml:id="id_38">
<xsl:value-of xml:id="id_42" select="nsmpr0:PNAME"/>
</nstrgdfl:Company>
<xsl:for-each select="fn:current-group()">
<nstrgdfl:Lines xml:id="id_37">
<nstrgdfl:c1d xml:id="id_43">
<xsl:value-of xml:id="id_44" select="nsmpr0:CID"/>
</nstrgdfl:c1d>
<nstrgdfl:cname xml:id="id_45">
<xsl:value-of xml:id="id_46" select="nsmpr0:CNAME"/>
</nstrgdfl:cname>
<nstrgdfl:cdesc xml:id="id_47">
<xsl:value-of xml:id="id_48" select="nsmpr0:CDESC"/>
</nstrgdfl:cdesc>
</nstrgdfl:Lines>
</xsl:for-each>
</nstrgdfl:DeliveryOrders>
</xsl:for-each-group>
</nstrgdfl:request-wrapper>
</nstrgmpr:WriteFile>
</xsl:template>
</xsl:stylesheet>
I was hoping to get help on the XPATH I'm trying to create.
I have the following file structure in XML:
<Request>
<RequestArea>
<SourceText>**Text 1**</SourceText>
</RequestArea>
<ResponseArea>
<TargetText></TargetText>
</ResponseArea>
</Request>
<Request>
<RequestArea>
<SourceText>**Text 2**</SourceText>
</RequestArea>
<ResponseArea>
<TargetText></TargetText>
</ResponseArea>
</Request>
I need to copy value of SourceText node and paste it into following TargetText node.
So, the resulting XML file would be this:
<Request>
<RequestArea>
<SourceText>**Text 1**</SourceText>
</RequestArea>
<ResponseArea>
<TargetText>**Text 1**</TargetText>
</ResponseArea>
</Request>
<Request>
<RequestArea>
<SourceText>**Text 2**</SourceText>
</RequestArea>
<ResponseArea>
<TargetText>**Text 2**</TargetText>
</ResponseArea>
</Request>
I have the following XSL:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<!-- identity transform -->
<xsl:template match="#*|node()">
<xsl:copy>
<xsl:apply-templates select="#*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="TargetText">
<ResponseText>
<xsl:value-of select="preceding::SourceText"/>
</ResponseText>
</xsl:template>
</xsl:stylesheet>
But the XSL engine (MSXSL) copies Text 1 value into both subsequent TargetText nodes instead of using each following SourceText value as a source for the content that gets copied:
<Request>
<RequestArea>
<SourceText>**Text 1**</SourceText>
</RequestArea>
<ResponseArea>
<TargetText>**Text 1**</TargetText>
</ResponseArea>
</Request>
<Request>
<RequestArea>
<SourceText>**Text 2**</SourceText>
</RequestArea>
<ResponseArea>
<TargetText>**Text 1**</TargetText>
</ResponseArea>
</Request>
Any suggestions on what I'm doing wrong?
Thank you!
Just replace the second template in your XSLT with
<xsl:template match="ResponseArea/TargetText">
<ResponseText>
<xsl:value-of select="../../RequestArea/SourceText"/>
</ResponseText>
</xsl:template>
If you need the element to be named TargetText like in your desired example output instead of ResponseText, just change it.
The output of the above code is:
<Request>
<RequestArea>
<SourceText>**Text 1**</SourceText>
</RequestArea>
<ResponseArea>
<ResponseText>**Text 1**</ResponseText>
</ResponseArea>
</Request>
<Request>
<RequestArea>
<SourceText>**Text 2**</SourceText>
</RequestArea>
<ResponseArea>
<ResponseText>**Text 2**</ResponseText>
</ResponseArea>
</Request>
I am pulling clob data from a JDBC server and the below is the sample format of the xml
1
<?xml version="1.0" encoding="utf-8"?>
<Sales_Posting>
<row>
<ORGANIZATION_ID>1</ORGANIZATION_ID>
<RTL_LOC_ID>269</RTL_LOC_ID>
<POSLOG_DATA><?xml version="1.0" encoding="UTF-8"?>
<POSLog xmlns="http://www.nrf-arts.org/IXRetail/namespace/"
xmlns:dtv="http://www.datavantagecorp.com/xstore/"
xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
xs:schemaLocation="http://www.nrf-arts.org/IXRetail/namespace/ POSLog.xsd" >
<Transaction xmlns:dtv="http://www.datavantagecorp.com/xstore/" CancelFlag="true" OfflineFlag="false" TrainingModeFlag="false" dtv:AppVersion="17.0.0.0.716 - 0.0.0 - 0.0" dtv:TransactionType="RETAIL_SALE" >
<dtv:OrganizationID><![CDATA[1]]></dtv:OrganizationID>
<RetailStoreID><![CDATA[269]]></RetailStoreID>
<WorkstationID><![CDATA[2]]></WorkstationID>
</Transaction>
</POSLog></POSLOG_DATA>
<CREATE_DATE>2019-07-17 20:57:56.536</CREATE_DATE>
</row>
<row>
<ORGANIZATION_ID>1</ORGANIZATION_ID>
<RTL_LOC_ID>269</RTL_LOC_ID>
<POSLOG_DATA><?xml version="1.0" encoding="UTF-8"?>
<POSLog xmlns="http://www.nrf-arts.org/IXRetail/namespace/"
xmlns:dtv="http://www.datavantagecorp.com/xstore/"
xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
xs:schemaLocation="http://www.nrf-arts.org/IXRetail/namespace/ POSLog.xsd" >
<Transaction xmlns:dtv="http://www.datavantagecorp.com/xstore/" CancelFlag="false" OfflineFlag="false" TrainingModeFlag="false" dtv:AppVersion="17.0.0.0.716 - 0.0.0 - 0.0" dtv:TransactionType="RETAIL_SALE" >
<dtv:OrganizationID><![CDATA[1]]></dtv:OrganizationID>
<RetailStoreID><![CDATA[269]]></RetailStoreID>
<WorkstationID><![CDATA[2]]></WorkstationID>
</Transaction>
</POSLog></POSLOG_DATA>
<CREATE_DATE>2019-07-18 06:20:38.014</CREATE_DATE>
</row>
</Sales_Posting>
I need to pull the xml inside the tag .
For a single record I am able to pull the data using the below code
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" indent="yes"/>
<xsl:template match="/">
<xsl:value-of select="/Sales_Posting/row/POSLOG_DATA"/>
</xsl:template>
</xsl:stylesheet>
But I require it for multiple records.
XSLT 1.0 is preferable. If the result is possible via multiple xslt mappings then that is also fine for me.
Expected Output is :-
2
<?xml version="1.0" encoding="utf-8"?>
<Sales_Posting>
<row>
<POSLog xmlns="http://www.nrf-arts.org/IXRetail/namespace/"
xmlns:dtv="http://www.datavantagecorp.com/xstore/"
xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
xs:schemaLocation="http://www.nrf-arts.org/IXRetail/namespace/ POSLog.xsd">
<Transaction CancelFlag="true"
OfflineFlag="false"
TrainingModeFlag="false"
dtv:AppVersion="17.0.0.0.716 - 0.0.0 - 0.0"
dtv:TransactionType="RETAIL_SALE">
<dtv:OrganizationID>1</dtv:OrganizationID>
<RetailStoreID>269</RetailStoreID>
<WorkstationID>2</WorkstationID>
</Transaction>
</POSLog>
</row>
<row>
<POSLog xmlns="http://www.nrf-arts.org/IXRetail/namespace/"
xmlns:dtv="http://www.datavantagecorp.com/xstore/"
xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
xs:schemaLocation="http://www.nrf-arts.org/IXRetail/namespace/ POSLog.xsd">
<Transaction CancelFlag="true"
OfflineFlag="false"
TrainingModeFlag="false"
dtv:AppVersion="17.0.0.0.716 - 0.0.0 - 0.0"
dtv:TransactionType="RETAIL_SALE">
<dtv:OrganizationID>1</dtv:OrganizationID>
<RetailStoreID>269</RetailStoreID>
<WorkstationID>2</WorkstationID>
</Transaction>
</POSLog>
</row>
</Sales_Posting>
I am sharing the image of source structure as well as the expected target structure. Kindly help.
Try:
XSLT 1.0
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/Sales_Posting">
<xsl:copy>
<xsl:for-each select="row">
<xsl:copy>
<xsl:value-of select="substring-after(POSLOG_DATA, '?>')" disable-output-escaping="yes"/>
</xsl:copy>
</xsl:for-each>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
The result must be saved to file before processed further. This is assuming your processor supports disable-output-escaping.