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>
Related
I have an xml that looks like below.
<?xml version="1.0" encoding="UTF-8"?>
<Invoice xsi:schemaLocation="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2 http://docs.oasis-open.org/ubl/os-UBL-2.1/xsd/maindoc/UBL-Invoice-2.1.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" xmlns:ext="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2" xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2">
<cac:InvoiceLine>
<cbc:ID></cbc:ID>
<cbc:LineExtensionAmount currencyID="EUR">93.46</cbc:LineExtensionAmount>
<cac:Item>
<cac:AdditionalItemProperty>
<cbc:Name>Total Hours</cbc:Name>
<cbc:Value>43</cbc:Value>
</cac:AdditionalItemProperty>
<cac:AdditionalItemProperty>
<cbc:Name>naamKandidaat</cbc:Name>
<cbc:Value>Kees Netelvrees</cbc:Value>
</cac:AdditionalItemProperty>
</cac:Item>
</cac:InvoiceLine>
<cac:InvoiceLine>
<cbc:ID></cbc:ID>
<cbc:LineExtensionAmount currencyID="EUR">2.77</cbc:LineExtensionAmount>
<cac:Item>
<cac:AdditionalItemProperty>
<cbc:Name>Total Hours</cbc:Name>
<cbc:Value>43</cbc:Value>
</cac:AdditionalItemProperty>
<cac:AdditionalItemProperty>
**<cbc:Name>naamKandidaat</cbc:Name>**
<cbc:Value>Jaap Aap</cbc:Value>
</cac:AdditionalItemProperty>
</cac:Item>
</cac:InvoiceLine>
<cac:InvoiceLine>
<cbc:ID></cbc:ID>
<cbc:LineExtensionAmount currencyID="EUR">100.00</cbc:LineExtensionAmount>
<cac:Item>
<cac:AdditionalItemProperty>
<cbc:Name>Total Hours</cbc:Name>
<cbc:Value>43</cbc:Value>
</cac:AdditionalItemProperty>
<cac:AdditionalItemProperty>
**<cbc:Name>naamKandidaat</cbc:Name>**
<cbc:Value>Jaap Aap</cbc:Value>
</cac:AdditionalItemProperty>
</cac:Item>
</cac:InvoiceLine>
</Invoice>
I need to group cac:InvoiceLine/cac:Item/cac:AdditionalItemProperty/cbc:Value where InvoiceLine/cac:Item/cac:AdditionalItemProperty/cbc:Name**=naamKandidaat**.
The purpose is to sum nodes within cac:InvoiceLine where cbc:Name is the same.
The problem is that I do not know how to create the key
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" xmlns:ccts="urn:un:unece:uncefact:documentation:2" xmlns:qdt="urn:oasis:names:specification:ubl:schema:xsd:QualifiedDatatypes-2" xmlns:udt="urn:un:unece:uncefact:data:specification:UnqualifiedDataTypesSchemaModule:2" xmlns:default="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2" exclude-result-prefixes="cac cbc ccts qdt udt default">
<xsl:output method="xml" encoding="utf-8" indent="yes"/>
<xsl:key name="PerAdditionalItemProperty" match="cac:InvoiceLine" use="cac:Item/cac:AdditionalItemProperty/cbc:Value"/>
<xsl:template match="/">
<PurchaseInvoices_version_1.0>
<xsl:for-each select="default:Invoice">
<PurchaseInvoice>
<xsl:for-each select="cac:InvoiceLine[generate-id(.)=generate-id(key('PerAdditionalItemProperty',cac:Item/cac:AdditionalItemProperty/cbc:Value)[1])]">
<xsl:for-each select="key('PerAdditionalItemProperty',cac:Item/cac:AdditionalItemProperty/cbc:Value)">
<xsl:if test="position()=1">
<Line>
<Item><xsl:value-of select="cac:Item/cac:AdditionalItemProperty/cbc:Value"/></Item>
<LineAmount><xsl:value-of select="format-number(sum(key('PerAdditionalItemProperty',cac:Item/cac:AdditionalItemProperty/cbc:Value)/cbc:LineExtensionAmount[number(.) = number(.)]),'#.##')"/></LineAmount>
</Line>
</xsl:if>
</xsl:for-each>
</xsl:for-each>
</PurchaseInvoice>
</xsl:for-each>
</PurchaseInvoices_version_1.0>
</xsl:template>
</xsl:stylesheet>
The output that I expect is:
<?xml version="1.0" encoding="utf-8"?>
<PurchaseInvoices_version_1.0>
<PurchaseInvoice>
<Line>
<Item>Kees Netelvrees</Item>
<LineAmount>93.46</LineAmount>
</Line>
<Line>
<Item>Jaap Aap</Item>
<LineAmount>102.77</LineAmount>
</Line>
</PurchaseInvoice>
</PurchaseInvoices_version_1.0
You just need to put the conditions into the key expression:
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"
xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2"
version="1.0">
<xsl:output indent="yes"/>
<xsl:key name="group" match="cac:InvoiceLine" use="cac:Item/cac:AdditionalItemProperty[cbc:Name = 'naamKandidaat']/cbc:Value"/>
<xsl:template match="cac:InvoiceLine[generate-id() = generate-id(key('group', cac:Item/cac:AdditionalItemProperty[cbc:Name = 'naamKandidaat']/cbc:Value)[1])]">
<Line>
<Item>
<xsl:value-of select="cac:Item/cac:AdditionalItemProperty[cbc:Name = 'naamKandidaat']/cbc:Value"/>
</Item>
<LineAmount>
<xsl:value-of select="sum(key('group', cac:Item/cac:AdditionalItemProperty[cbc:Name = 'naamKandidaat']/cbc:Value)/cbc:LineExtensionAmount)"/>
</LineAmount>
</Line>
</xsl:template>
<xsl:template match="cac:InvoiceLine[not(generate-id() = generate-id(key('group', cac:Item/cac:AdditionalItemProperty[cbc:Name = 'naamKandidaat']/cbc:Value)[1]))]"/>
<xsl:template match="/">
<PurchaseInvoices_version_1.0>
<PurchaseInvoice>
<xsl:apply-templates/>
</PurchaseInvoice>
</PurchaseInvoices_version_1.0>
</xsl:template>
</xsl:stylesheet>
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
Team,
Need your help in grouping data in XSLT.
Requirements:
Group data based on report_number
Group step 1 output data based on program_name
Iterate through each of grouped data and create XML as in expected output
I am able to execute first two steps. I am not able to arrive at a logic
for step 3.
Input:
<?xml version="1.0" ?>
<MTR>
<program>
<program_row>
<report_number>1</report_number>
<program_id>PMP</program_id>
<program_name>Portfolio Manager Program</program_name>
<ssn_tin>1111111111</ssn_tin>
<acct_number>1111111111</acct_number>
<total_value/>
</program_row>
<program_row>
<report_number>1</report_number>
<program_id>PMP</program_id>
<program_name>Portfolio Manager Program</program_name>
<ssn_tin>2222222222</ssn_tin>
<acct_number>2222222222</acct_number>
<total_value/>
</program_row>
<program_row>
<report_number>1</report_number>
<program_id>PMP</program_id>
<program_name>Customer Manager Program</program_name>
<ssn_tin>3333333333</ssn_tin>
<acct_number>3333333333</acct_number>
<total_value/>
</program_row>
<program_row>
<report_number>1</report_number>
<program_id>PMP</program_id>
<program_name>Portfolio Manager Program</program_name>
<ssn_tin>4444444444</ssn_tin>
<acct_number>4444444444</acct_number>
<total_value/>
</program_row>
<program_row>
<report_number>1</report_number>
<program_id>PMP</program_id>
<program_name>Relationship Manager Program</program_name>
<ssn_tin>55555555555</ssn_tin>
<acct_number>55555555555</acct_number>
<total_value/>
</program_row>
<program_row>
<report_number>2</report_number>
<program_id>PMP</program_id>
<program_name>Ringo Manager Program</program_name>
<ssn_tin>6666666666</ssn_tin>
<acct_number>6666666666</acct_number>
<total_value/>
</program_row>
</program>
</MTR>
Expected Output:
<?xml version="1.0" encoding="UTF-8"?>
<MTR>
<reports>
<report>
<report_number>1</report_number>
<headers>
<header>
<prog_name>Portfolio Manager Program</prog_name>
<acct_no>1111111111,2222222222,55555555555</acct_no>
</header>
<header>
<prog_name>Customer Manager Program</prog_name>
<acct_no>3333333333</acct_no>
</header>
<header>
<prog_name>Relationship Manager Program</prog_name>
<acct_no>4444444444</acct_no>
</header>
</headers>
</report>
<report>
<report_number>2</report_number>
<headers>
<header>
<prog_name>Ringo Manager Program</prog_name>
<acct_no>6666666666</acct_no>
</header>
</headers>
</report>
</reports>
</MTR>
Incomplete XSLT:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" />
<xsl:key name="kGroup" match="program_row" use="report_number"/>
<xsl:key name="progNameGroup" match="program_row" use="program_name"/>
<xsl:template match="MTR">
<MTR>
<xsl:copy-of select="emb_disc" />
<xsl:copy-of select="emb_foot_note" />
<reports>
<xsl:for-each select="program/program_row[generate-id(.) = generate-id(key('kGroup', report_number)[1])]">
<report>
<headers>
<xsl:for-each select="key('kGroup', report_number)[generate-id() = generate-id(key('progNameGroup', program_name)[1])]">
<xsl:for-each select="key('progNameGroup', program_name)">
<header>
<prog_name></prog_name>
<acct_no></acct_no>
</header>
</xsl:for-each>
</xsl:for-each>
</headers>
</report>
</xsl:for-each>
</reports>
</MTR>
</xsl:template>
</xsl:stylesheet>
Here is a correction, you need to make sure the second-level key includes the value of the first-level key and then you need to output the items:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" />
<xsl:key name="kGroup" match="program_row" use="report_number"/>
<xsl:key name="progNameGroup" match="program_row" use="concat(report_number, '|', program_name)"/>
<xsl:template match="MTR">
<MTR>
<xsl:copy-of select="emb_disc" />
<xsl:copy-of select="emb_foot_note" />
<reports>
<xsl:for-each select="program/program_row[generate-id(.) = generate-id(key('kGroup', report_number)[1])]">
<report>
<xsl:copy-of select="report_number"/>
<headers>
<xsl:for-each select="key('kGroup', report_number)[generate-id() = generate-id(key('progNameGroup', concat(report_number, '|', program_name))[1])]">
<header>
<prog_name><xsl:value-of select="program_name"/></prog_name>
<acct_no>
<xsl:for-each select="key('progNameGroup', concat(report_number, '|', program_name))/acct_number">
<xsl:if test="position() > 1">,</xsl:if>
<xsl:value-of select="."/>
</xsl:for-each>
</acct_no>
</header>
</xsl:for-each>
</headers>
</report>
</xsl:for-each>
</reports>
</MTR>
</xsl:template>
</xsl:stylesheet>
Online sample at http://xsltransform.net/6qVRKx9.
I have a xml document which looks like
<!-- language: lang-xml -->
<?xml version="1.0" encoding="UTF-8"?>
<Request xmlns="fst" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Header>
<AccountServer e-dtype="int">3</AccountServer>
</Header>
<Response>
<ResponseList e-dtype="list">
<Response>
<RequestId e-dtype="string">ServiceOrderGetRef</RequestId>
<RequestObjName e-dtype="string">ServiceOrder</RequestObjName>
<ServiceOrder>
<CreateDt e-dtype="dateTime">2014-03-01 00:00:00</CreateDt>
<CreateWho e-dtype="string">vc</CreateWho>
<WorkflowStartDt e-dtype="dateTime">2014-04-01 00:00:00</WorkflowStartDt>
</ServiceOrder>
</Response>
<Response>
<ComponentList e-dtype="list"/>
<Count e-dtype="int">0</Count>
<RequestId e-dtype="string">ComponentFindRef</RequestId>
<RequestObjName e-dtype="string">Component</RequestObjName>
<TotalCount e-dtype="int">0</TotalCount>
</Response>
<Response>
<Count e-dtype="int">0</Count>
<CustomerContractList e-dtype="list"/>
<RequestId e-dtype="string">CustomerContractRef</RequestId>
<RequestObjName e-dtype="string">CustomerContract</RequestObjName>
<TotalCount e-dtype="int">0</TotalCount>
</Response>
<Response>
<Count e-dtype="int">0</Count>
<ProductList e-dtype="list"/>
<RequestId e-dtype="string">ProductRef</RequestId>
<RequestObjName e-dtype="string">Product</RequestObjName>
<TotalCount e-dtype="int">0</TotalCount>
</Response>
<Response>
<Count e-dtype="int">0</Count>
<NrcList e-dtype="list"/>
<RequestId e-dtype="string">NrcFindRef</RequestId>
<RequestObjName e-dtype="string">Nrc</RequestObjName>
<TotalCount e-dtype="int">0</TotalCount>
</Response>
</ResponseList>
</Response>
</Request>
I am using copy-of function to copy node ServiceOrder within another xml document
I want to modify text of node WorkFlowStartDt and CreateDt and then do a copy-of. How can I do this?
My copied serviceorder node should look like this after modifing text. Below is the result xml
<?xml version="1.0" encoding="UTF-8"?>
<Request>
<Header>
<OperatorName e-dtype="string">ws</OperatorName>
<ApplicationName e-dtype="string">ws</ApplicationName>
</Header>
<CustomerUdtRequest>
<RequestList e-dtype="list">
<LogicalServiceOrder>
<RequestId e-dtype="string">MyExistingOrder</RequestId>
<LogicalServiceOrderPreProcess>
<Fetch e-dtype="boolean">true</Fetch>
<Order>
<AccountInternalId e-dtype="int">12345</AccountInternalId>
<Key>
<OrderId e-dtype="numeric">12345678</OrderId>
</Key>
</Order>
<ServiceOrderList e-dtype="list">
<ServiceOrder xmlns="fst" xmlns:xsi="http://www.w3.org/2001/XMLSchema-
instance">
<CreateDt e-dtype="dateTime">2014-03-02 00:00:00</CreateDt>
<CreateWho e-dtype="string">vc</CreateWho>
<WorkflowStartDt e-dtype="dateTime">2014-05-01 00:00:00</WorkflowStartDt>
</ServiceOrder>
</ServiceOrderList>
</LogicalServiceOrderPreProcess>
</LogicalServiceOrder>
</RequestList>
</CustomerUdtRequest>
</Request>
Below is my xslt processor file
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml"/>
<xsl:template match="/">
<Request>
<Header>
<OperatorName e-dtype="string">ws</OperatorName>
<ApplicationName e-dtype="string">ws</ApplicationName>
</Header>
<CustomerUdtRequest>
<RequestList e-dtype="list">
<LogicalServiceOrder>
<RequestId e-dtype="string">MyExistingOrder</RequestId>
<LogicalServiceOrderPreProcess> <Order> <AccountInternalId e-dtype="int">
<xsl:value-of
select="/Request/Response/ResponseList/Response/ServiceOrder/AccountInternalId"/>
</AccountInternalId> <Key> <OrderId e-dtype="numeric"> <xsl:value-of select="/Request/Response/ResponseList/Response/ServiceOrder/OrderId"/>
</OrderId>
</Key>
</Order>
<ServiceOrderList e-dtype="list">
<xsl:copy-of select="/Request/Response/ResponseList/Response/ServiceOrder"/>
</ServiceOrderList>
</LogicalServiceOrderPreProcess>
</LogicalServiceOrder>
</xsl:if>
</RequestList>
</CustomerUdtRequest>
</Request>
</xsl:template>
</xsl:stylesheet>
I want to modify text of node WorkFlowStartDt and CreateDt and then do
a copy-of.
That would be an unnecessary complication. You can modify nodes while you add them to the output tree.
Since you essentially want to copy everything "as is" except two nodes, it would be best to start with an identity transform template, then add an "exception" template for the two specific nodes that need modifying (one template for both, since the modification is identical).:
<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 transformation -->
<xsl:template match="#*|node()">
<xsl:copy>
<xsl:apply-templates select="#*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="CreateDt | WorkFlowStartDt">
<xsl:copy>
<xsl:value-of select="concat('**', ., '**')"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Added:
In response to the edited question, try this stylesheet:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ns="fst"
exclude-result-prefixes="ns">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<Request>
<Header>
<OperatorName e-dtype="string">ws</OperatorName>
<ApplicationName e-dtype="string">ws</ApplicationName>
</Header>
<CustomerUdtRequest>
<RequestList e-dtype="list">
<LogicalServiceOrder>
<RequestId e-dtype="string">MyExistingOrder</RequestId>
<LogicalServiceOrderPreProcess>
<Order>
<AccountInternalId e-dtype="int">
<!-- THIS DOESN'T POINT TO ANY EXISTING NODE!! -->
<xsl:value-of select="ns:Request/ns:Response/ns:ResponseList/ns:Response/ns:ServiceOrder/ns:AccountInternalId"/>
</AccountInternalId>
<Key>
<OrderId e-dtype="numeric">
<!-- THIS DOESN'T POINT TO ANY EXISTING NODE!! -->
<xsl:value-of select="ns:Request/ns:Response/ns:ResponseList/ns:Response/ns:ServiceOrder/ns:OrderId"/>
</OrderId>
</Key>
</Order>
<xsl:apply-templates select="ns:Request/ns:Response/ns:ResponseList/ns:Response/ns:ServiceOrder"/>
</LogicalServiceOrderPreProcess>
</LogicalServiceOrder>
</RequestList>
</CustomerUdtRequest>
</Request>
</xsl:template>
<xsl:template match="ns:ServiceOrder">
<xsl:copy>
<xsl:copy-of select="ns:CreateWho"/>
<xsl:apply-templates select="ns:CreateDt | ns:WorkflowStartDt"/>
</xsl:copy>
</xsl:template>
<xsl:template match="ns:CreateDt | ns:WorkflowStartDt">
<xsl:copy>
<xsl:copy-of select="#*"/>
<xsl:value-of select="concat('**', ., '**')"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
When applied to your input (minus the illegal opening comment), the following result is obtained:
<?xml version="1.0" encoding="UTF-8"?>
<Request>
<Header>
<OperatorName e-dtype="string">ws</OperatorName>
<ApplicationName e-dtype="string">ws</ApplicationName>
</Header>
<CustomerUdtRequest>
<RequestList e-dtype="list">
<LogicalServiceOrder>
<RequestId e-dtype="string">MyExistingOrder</RequestId>
<LogicalServiceOrderPreProcess>
<Order>
<AccountInternalId e-dtype="int"/>
<Key>
<OrderId e-dtype="numeric"/>
</Key>
</Order>
<ServiceOrder xmlns="fst" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<CreateWho e-dtype="string">vc</CreateWho>
<CreateDt e-dtype="dateTime">**2014-03-01 00:00:00**</CreateDt>
<WorkflowStartDt e-dtype="dateTime">**2014-04-01 00:00:00**</WorkflowStartDt>
</ServiceOrder>
</LogicalServiceOrderPreProcess>
</LogicalServiceOrder>
</RequestList>
</CustomerUdtRequest>
</Request>
I am trying to apply a transformation to generate an rdf document. My source xml contains an element that I want to ignore, but the output (generated via SAP's transformation test tool) includes the (concatenated!) texts of the elements from SYSINFO.
I have tried several variations (such as xsl:apply-templates select="asx:abap/asx:/values/CT" )
but then I get no output at all. Hmm. Have spent several hours trying different things and researching, but have gotten nowhere. Any help really appreciated. John
Here is my sample xml (fragment)
<?xml version="1.0" encoding="utf-8"?>
<asx:abap xmlns:asx="http://www.sap.com/abapxml"version="1.0">
<asx:values>
<SYSINFO>
<SERVER_NAME>sapserver06</SERVER_NAME>
<SYSTEM_ID>ECC</SYSTEM_ID>
<SAP_RELEASE>701</SAP_RELEASE>
<SYS_NR>00</SYS_NR>
<CLIENT>800</CLIENT>
<EXE_USER>XXX</EXE_USER>
<LOGON_LANGUAGE>E</LOGON_LANGUAGE>
<DATE>2013-04-09</DATE>
<TIME>12:06:58</TIME>
<TIMEZONE>CST</TIMEZONE>
<OPERATING_SYSTEM>Windows NT</OPERATING_SYSTEM>
<LICENSE_NUMBER>YYY</LICENSE_NUMBER>
<SAP_CUSTOMER>ZZZ</SAP_CUSTOMER>
<CLIENT_CATEGORY>C</CLIENT_CATEGORY>
<LANGUAGES_INSTALLED>JED</LANGUAGES_INSTALLED>
</SYSINFO>
<CT>
<item>
<ID>1</ID>
<TABNAME>T000</TABNAME>
<FIELDNAME>ADRNR</FIELDNAME>
<KEYFLAG/>
<ROLLNAME>CHAR10</ROLLNAME>
</item>
.....
</CT>
</asx:values>
</asx:abap>
Here is the transformation
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:sap="http://www.sap.com/sapxsl" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:sap_coda="http://www.sapmantics.com/sap_coda#" version="1.0">
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<rdf:RDF>
<xsl:apply-templates/>
</rdf:RDF>
</xsl:template>
<xsl:template>
<xsl:for-each select="//item">
<rdf:Description>
<xsl:attribute name="rdf:about">
<xsl:value-of select="TABNAME"/>
</xsl:attribute>
<rdf:type rdf:resource="http://www.sapmantics.com/sap_coda#ctable"/>
<sap_coda:t2f>
<rdf:Description>
<xsl:attribute name="rdf:about">
<xsl:value-of select="FIELDNAME"/>
</xsl:attribute>
<rdf:type rdf:resource="http://www.sapmantics.com/sap_coda#cfield"/>
<xsl:if test="KEYFLAG=X">
<sap_coda:keyflag>X</sap_coda:keyflag>
</xsl:if>
</rdf:Description>
</sap_coda:t2f>
</rdf:Description>
</xsl:for-each>
</xsl:template>
</xsl:transform>
And finally, here is the output:
<?xml version="1.0" encoding="utf-16"?>
sapserver06ECC70100800XXXE2013-04-0917:21:50CSTWindowsNTYYYZZZCJED
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:sap_coda="http://www.sapmantics.com/sap_coda#">
<rdf:Description rdf:about="T000">
<rdf:type rdf:resource="http://www.sapmantics.com/sap_coda#ctable"/>....
The concatenation of your <SYSINFO/> text nodes can be explained by the default handing for element nodes:
http://www.w3.org/TR/xslt#built-in-rule
I don't know which XSLT processor you are using, but I am surprised that your //item handler wasn't flagged for lacking a #match attribute. You can update it with the following, and it will handle each <item/> element in document order:
<xsl:template match="item">
<rdf:Description>
To keep your SYSINFO content from being included in your RDF (if that is your intent), update your root template with the following:
<rdf:RDF>
<xsl:apply-templates select="//item"/>
</rdf:RDF>
-----------EDIT--------------------------
With this input
<?xml version="1.0" encoding="utf-8"?>
<asx:abap xmlns:asx="http://www.sap.com/abapxml">
<asx:values>
<SYSINFO>
<SERVER_NAME>sapserver06</SERVER_NAME>
<SYSTEM_ID>ECC</SYSTEM_ID>
<SAP_RELEASE>701</SAP_RELEASE>
<SYS_NR>00</SYS_NR>
<CLIENT>800</CLIENT>
<EXE_USER>XXX</EXE_USER>
<LOGON_LANGUAGE>E</LOGON_LANGUAGE>
<DATE>2013-04-09</DATE>
<TIME>12:06:58</TIME>
<TIMEZONE>CST</TIMEZONE>
<OPERATING_SYSTEM>Windows NT</OPERATING_SYSTEM>
<LICENSE_NUMBER>YYY</LICENSE_NUMBER>
<SAP_CUSTOMER>ZZZ</SAP_CUSTOMER>
<CLIENT_CATEGORY>C</CLIENT_CATEGORY>
<LANGUAGES_INSTALLED>JED</LANGUAGES_INSTALLED>
</SYSINFO>
<CT>
<item>
<ID>1</ID>
<TABNAME>T000</TABNAME>
<FIELDNAME>ADRNR</FIELDNAME>
<KEYFLAG/>
<ROLLNAME>CHAR10</ROLLNAME>
</item>
</CT>
</asx:values>
</asx:abap>
and this stylesheet
<?xml version="1.0" encoding="UTF-8"?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:sap="http://www.sap.com/sapxsl"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:sap_coda="http://www.sapmantics.com/sap_coda#"
version="1.0">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<rdf:RDF>
<xsl:apply-templates select="//item"/>
</rdf:RDF>
</xsl:template>
<xsl:template match="item[parent::CT]">
<rdf:Description>
<xsl:attribute name="rdf:about">
<xsl:value-of select="TABNAME"/>
</xsl:attribute>
<rdf:type rdf:resource="http://www.sapmantics.com/sap_coda#ctable"/>
<sap_coda:t2f>
<rdf:Description>
<xsl:attribute name="rdf:about">
<xsl:value-of select="FIELDNAME"/>
</xsl:attribute>
<rdf:type rdf:resource="http://www.sapmantics.com/sap_coda#cfield"/>
<xsl:if test="KEYFLAG=X">
<sap_coda:keyflag>X</sap_coda:keyflag>
</xsl:if>
</rdf:Description>
</sap_coda:t2f>
</rdf:Description>
</xsl:template>
<xsl:template match="item[parent::FOO]"/>
<xsl:template match="item"/>
</xsl:transform>
I get this output from Saxon-EE 9.4.0.3:
<?xml version="1.0" encoding="UTF-8"?>
<rdf:RDF xmlns:sap="http://www.sap.com/sapxsl"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:sap_coda="http://www.sapmantics.com/sap_coda#">
<rdf:Description rdf:about="T000">
<rdf:type rdf:resource="http://www.sapmantics.com/sap_coda#ctable"/>
<sap_coda:t2f>
<rdf:Description rdf:about="ADRNR">
<rdf:type rdf:resource="http://www.sapmantics.com/sap_coda#cfield"/>
</rdf:Description>
</sap_coda:t2f>
</rdf:Description>
</rdf:RDF>
and this output from xstlproc:
<?xml version="1.0"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:sap="http://www.sap.com/sapxsl" xmlns:sap_coda="http://www.sapmantics.com/sap_coda#">
<rdf:Description rdf:about="T000">
<rdf:type rdf:resource="http://www.sapmantics.com/sap_coda#ctable"/>
<sap_coda:t2f>
<rdf:Description rdf:about="ADRNR">
<rdf:type rdf:resource="http://www.sapmantics.com/sap_coda#cfield"/>
</rdf:Description>
</sap_coda:t2f>
</rdf:Description>
</rdf:RDF>