Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XSLT: xsi:schemaLocation is not showing on XML

Tags:

xslt

I am trying to do a transformation but I am having an issue with the xsi:schemaLocation not showing on the XML result. I have searched all over why this is happening and I just can't seem to find it. Please help

Input XML

<asx:abap version="1.0" xmlns:asx="http://www.sap.com/abapxml">
<asx:values>
    <_--5CCLASS_--3DZCL_T4_NOM_--5CTYPE_--3DTT_SAP_REQ>
        <item>
            <TECHNICAL_KEY>00006000000000326391</TECHNICAL_KEY>
            <TSCARRIER>CPL</TSCARRIER>
            <MATERIAL>V2</MATERIAL>
            <PIPELINE_CYCLE>45</PIPELINE_CYCLE>
            <PIPELINE_SEQUENCE>1</PIPELINE_SEQUENCE>
            <CYCLE_YEAR>2012</CYCLE_YEAR>
            <SCD/>
            <NOM_NUMBER>CITV2451</NOM_NUMBER>
            <DATE_TIME>2012-06-20T00:00:00</DATE_TIME>
            <CREATE_DATE_TIME>2012-06-06T18:01:18</CREATE_DATE_TIME>
            <TOTAL_ITEMS>1 </TOTAL_ITEMS>
            <T4NOMNR/>
            <ITEM_NUMBER>0000000010</ITEM_NUMBER>
            <ITEM_DETAIL_CHANGE_CODE/>
            <PIPELINE_EVENT>Delivery</PIPELINE_EVENT>
            <PIPELINE_EVENT_AFFECT>Decrease</PIPELINE_EVENT_AFFECT>
            <QUANTITY>25000.00</QUANTITY>
            <UOM>BR</UOM>
            <LOCATION>AHT</LOCATION>
            <LOCATION_PARTNER>AHT</LOCATION_PARTNER>
            <CONTRACT_PARTNER/>
            <SUPPLIER/>
            <TANKAGE_PARTNER>KM1</TANKAGE_PARTNER>
            <CONSIGNEE_PARTNER>CIT</CONSIGNEE_PARTNER>
            <CONS_SUPPLIER>Consignee</CONS_SUPPLIER>
            <TRANSPURIND>Add</TRANSPURIND>
            <VERSION>1</VERSION>
            <PARTROLEIND>Shipper</PARTROLEIND>
            <SHIPPARTID>CIT</SHIPPARTID>
            <PART_IDENTIFIER>AssignedByCarrier</PART_IDENTIFIER>
            <PROD_IDENTIFIER>AssignedByMarketplace</PROD_IDENTIFIER>
            <PART_TANKAGE>Tankage</PART_TANKAGE>
            <CARRIER_STRING>Carrier</CARRIER_STRING>
            <SHIPNOMNRSTRING>ShipperNominationNumber</SHIPNOMNRSTRING>
        </item>
    </_--5CCLASS_--3DZCL_T4_NOM_--5CTYPE_--3DTT_SAP_REQ>
</asx:values>

XSLT Code

    <?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns="http://www.api.org/pidXML/v1.2" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:pidx="http://www.api.org/pidXML/v1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.api.org/pidXML/v1.2 https://www.transport4.com/xml/schemas/PipelineNominationCreateV1-3.xsd">
    <xsl:template match="/">
        <xsl:element name="pidx:PipelineNominationCreate">
            <xsl:attribute name="pidx:documentIdentifier"><xsl:value-of select="//TECHNICAL_KEY"/></xsl:attribute>
            <xsl:attribute name="pidx:transactionPurposeIndicator"><xsl:value-of select="//TRANSPURIND"/></xsl:attribute>
            <xsl:attribute name="pidx:version"><xsl:value-of select="//VERSION"/></xsl:attribute>
            <xsl:element name="pidx:PipelineNominationCreateProperties">
                <xsl:element name="pidx:CreatedByPartner">
                    <xsl:element name="pidx:PartnerInformation">
                        <xsl:attribute name="partnerRoleIndicator"><xsl:value-of select="//PARTROLEIND"/></xsl:attribute>
                        <xsl:element name="pidx:PartnerIdentifier">
                            <xsl:attribute name="partnerIdentifierIndicator"><xsl:value-of select="//PART_IDENTIFIER"/></xsl:attribute>
                            <xsl:value-of select="//SHIPPARTID"/>
                        </xsl:element>
                    </xsl:element>
                    <xsl:element name="pidx:EventDateTime">
                        <xsl:value-of select="//CREATE_DATE_TIME"/>
                    </xsl:element>
                </xsl:element>
                <xsl:element name="pidx:PartnerInformation">
                    <xsl:attribute name="partnerRoleIndicator"><xsl:value-of select="//PARTROLEIND"/></xsl:attribute>
                    <xsl:element name="pidx:PartnerIdentifier">
                        <xsl:attribute name="partnerIdentifierIndicator"><xsl:value-of select="//PART_IDENTIFIER"/></xsl:attribute>
                        <xsl:value-of select="//SHIPPARTID"/>
                    </xsl:element>
                </xsl:element>
                <xsl:element name="pidx:PartnerInformation">
                    <xsl:attribute name="partnerRoleIndicator"><xsl:value-of select="//CARRIER_STRING"/></xsl:attribute>
                    <xsl:element name="pidx:PartnerIdentifier">
                        <xsl:attribute name="partnerIdentifierIndicator"><xsl:value-of select="//PART_IDENTIFIER"/></xsl:attribute>
                        <xsl:value-of select="//TSCARRIER"/>
                    </xsl:element>
                </xsl:element>
                <xsl:element name="pidx:ProductInformation">
                    <xsl:element name="pidx:ProductIdentifier">
                        <xsl:attribute name="assigningOrganization"><xsl:value-of select="//PROD_IDENTIFIER"/></xsl:attribute>
                        <xsl:value-of select="//MATERIAL"/>
                    </xsl:element>
                </xsl:element>
                <xsl:element name="pidx:PipelineCycle">
                    <xsl:value-of select="//PIPELINE_CYCLE"/>
                </xsl:element>
                <xsl:element name="pidx:PipelineCycleYear">
                    <xsl:value-of select="//CYCLE_YEAR"/>
                </xsl:element>
                <xsl:element name="pidx:PipelineSequence">
                    <xsl:value-of select="//PIPLELINE_SEQUENCE"/>
                </xsl:element>
                <xsl:element name="pidx:PipelineSCD">
                    <xsl:value-of select="//SCD"/>
                </xsl:element>
                <xsl:element name="pidx:ReferenceInformation">
                    <xsl:attribute name="referenceInformationIndicator"><xsl:value-of select="//SHIPNOMNRSTRING"/></xsl:attribute>
                    <xsl:element name="pidx:ReferenceNumber">
                        <xsl:value-of select="//NOM_NUMBER"/>
                    </xsl:element>
                    <xsl:element name="pidx:Description">
                    </xsl:element>
                </xsl:element>
            </xsl:element>
            <xsl:element name="pidx:PipelineNominationCreateDetails">
                <xsl:for-each select="//item">
                    <xsl:element name="pidx:PipelineNominationCreateLineItem">
                        <xsl:element name="pidx:LineItemNumber">
                            <xsl:value-of select="ITEM_NUMBER"/>
                        </xsl:element>
                        <xsl:element name="pidx:LineItemNominationQuantity">
                            <xsl:element name="pidx:Quantity">
                                <xsl:value-of select="QUANTITY"/>
                            </xsl:element>
                            <xsl:element name="pidx:UnitOfMeasureCode">
                                <xsl:value-of select="UOM"/>
                            </xsl:element>
                        </xsl:element>
                        <xsl:element name="pidx:PartnerInformation">
                            <xsl:attribute name="partnerRoleIndicator"><xsl:value-of select="CONS_SUPPLIER"/></xsl:attribute>
                            <xsl:element name="pidx:PartnerIdentifier">
                                <xsl:attribute name="partnerIdentifierIndicator"><xsl:value-of select="//PART_IDENTIFIER"/></xsl:attribute>
                                <xsl:value-of select="CONSIGNEE_PARTNER"/>
                            </xsl:element>
                        </xsl:element>
                        <xsl:element name="pidx:PartnerInformation">
                            <xsl:attribute name="partnerRoleIndicator"><xsl:value-of select="PART_TANKAGE"/></xsl:attribute>
                            <xsl:element name="pidx:PartnerIdentifier">
                                <xsl:attribute name="partnerIdentifierIndicator"><xsl:value-of select="//PART_IDENTIFIER"/></xsl:attribute>
                                <xsl:value-of select="TANKAGE_PARTNER"/>
                            </xsl:element>
                        </xsl:element>
                        <xsl:element name="pidx:ScheduleStartDateTime">
                            <xsl:value-of select="DATE_TIME"/>
                        </xsl:element>
                        <xsl:element name="pidx:ScheduleRequestDateTime">
                    </xsl:element>
                        <xsl:element name="pidx:PipelineEventInformation">
                            <xsl:element name="pidx:PipelineEvent">
                                <xsl:value-of select="PIPELINE_EVENT"/>
                            </xsl:element>
                            <xsl:element name="pidx:PipelineEventVolumeAffect">
                                <xsl:value-of select="PIPELINE_EVENT_AFFECT"/>
                            </xsl:element>
                        </xsl:element>
                        <xsl:element name="pidx:CustodyLocationInformation">
                            <xsl:element name="pidx:CustodyLocationIdentifier">
                                <xsl:attribute name="identifierIndicator"><xsl:value-of select="//PART_IDENTIFIER"/></xsl:attribute>
                                <xsl:value-of select="LOCATION_PARTNER"/>
                            </xsl:element>
                        </xsl:element>
                        <xsl:element name="pidx:ReferenceInformation">
                            <xsl:attribute name="referenceInformationIndicator">
                        </xsl:attribute>
                            <xsl:element name="pidx:ReferenceNumber">
                        </xsl:element>
                            <xsl:element name="pidx:Description">
                        </xsl:element>
                        </xsl:element>
                        <xsl:element name="pidx:Comment">
                        </xsl:element>
                    </xsl:element>
                </xsl:for-each>
            </xsl:element>
            <xsl:element name="pidx:PipelineNominationCreateSummary">
                <xsl:element name="pidx:TotalLineItems">
                    <xsl:value-of select="//TOTAL_ITEMS"/>
                </xsl:element>
            </xsl:element>
        </xsl:element>
    </xsl:template>
</xsl:stylesheet>

Result XML with missing schemaLocation

    <?xml version="1.0" encoding="iso-8859-1"?>
<pidx:PipelineNominationCreate xmlns:pidx="http://www.api.org/pidXML/v1.2" xmlns="http://www.api.org/pidXML/v1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" pidx:documentIdentifier="00006000000000326391" pidx:transactionPurposeIndicator="Add" pidx:version="1">
    <pidx:PipelineNominationCreateProperties>
        <pidx:CreatedByPartner>
            <pidx:PartnerInformation partnerRoleIndicator="Shipper">
                <pidx:PartnerIdentifier partnerIdentifierIndicator="AssignedByCarrier">CIT</pidx:PartnerIdentifier>
            </pidx:PartnerInformation>
            <pidx:EventDateTime>2012-06-07T15:55:35</pidx:EventDateTime>
        </pidx:CreatedByPartner>
        <pidx:PartnerInformation partnerRoleIndicator="Shipper">
            <pidx:PartnerIdentifier partnerIdentifierIndicator="AssignedByCarrier">CIT</pidx:PartnerIdentifier>
        </pidx:PartnerInformation>
        <pidx:PartnerInformation partnerRoleIndicator="Carrier">
            <pidx:PartnerIdentifier partnerIdentifierIndicator="AssignedByCarrier">CPL</pidx:PartnerIdentifier>
        </pidx:PartnerInformation>
        <pidx:ProductInformation>
            <pidx:ProductIdentifier assigningOrganization="AssignedByMarketplace">V2</pidx:ProductIdentifier>
        </pidx:ProductInformation>
        <pidx:PipelineCycle>45</pidx:PipelineCycle>
        <pidx:PipelineCycleYear>2012</pidx:PipelineCycleYear>
        <pidx:PipelineSequence/>
        <pidx:PipelineSCD/>
        <pidx:ReferenceInformation referenceInformationIndicator="ShipperNominationNumber">
            <pidx:ReferenceNumber>CITV2451</pidx:ReferenceNumber>
            <pidx:Description/>
        </pidx:ReferenceInformation>
    </pidx:PipelineNominationCreateProperties>
    <pidx:PipelineNominationCreateDetails>
        <pidx:PipelineNominationCreateLineItem>
            <pidx:LineItemNumber>0000000010</pidx:LineItemNumber>
            <pidx:LineItemNominationQuantity>
                <pidx:Quantity>25000.0</pidx:Quantity>
                <pidx:UnitOfMeasureCode>BR</pidx:UnitOfMeasureCode>
            </pidx:LineItemNominationQuantity>
            <pidx:PartnerInformation partnerRoleIndicator="Consignee">
                <pidx:PartnerIdentifier partnerIdentifierIndicator="AssignedByCarrier">CIT</pidx:PartnerIdentifier>
            </pidx:PartnerInformation>
            <pidx:PartnerInformation partnerRoleIndicator="Tankage">
                <pidx:PartnerIdentifier partnerIdentifierIndicator="AssignedByCarrier">KM1</pidx:PartnerIdentifier>
            </pidx:PartnerInformation>
            <pidx:ScheduleStartDateTime>2012-06-20T00:00:00</pidx:ScheduleStartDateTime>
            <pidx:ScheduleRequestDateTime/>
            <pidx:PipelineEventInformation>
                <pidx:PipelineEvent>Delivery</pidx:PipelineEvent>
                <pidx:PipelineEventVolumeAffect>Decrease</pidx:PipelineEventVolumeAffect>
            </pidx:PipelineEventInformation>
            <pidx:CustodyLocationInformation>
                <pidx:CustodyLocationIdentifier identifierIndicator="AssignedByCarrier">AHT</pidx:CustodyLocationIdentifier>
            </pidx:CustodyLocationInformation>
            <pidx:ReferenceInformation referenceInformationIndicator="">
                <pidx:ReferenceNumber/>
                <pidx:Description/>
            </pidx:ReferenceInformation>
            <pidx:Comment/>
        </pidx:PipelineNominationCreateLineItem>
    </pidx:PipelineNominationCreateDetails>
    <pidx:PipelineNominationCreateSummary>
        <pidx:TotalLineItems>1 </pidx:TotalLineItems>
    </pidx:PipelineNominationCreateSummary>
</pidx:PipelineNominationCreate>

Any help would be appreciated.

Thanks!

like image 344
user1443308 Avatar asked Dec 21 '22 20:12

user1443308


2 Answers

You have defined xsi:schemaLocation in your XSLT document, but nowhere in your XSLT do you attempt to create it in the XML document. It will not automatically be added to your output document. You will need to create it.

You can copy the xsi:schemaLocation attribute from the XSLT document like this:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" 
  xmlns="http://www.api.org/pidXML/v1.2" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
  xmlns:pidx="http://www.api.org/pidXML/v1.2" 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  xsi:schemaLocation="http://www.api.org/pidXML/v1.2 https://www.transport4.com/xml/schemas/PipelineNominationCreateV1-3.xsd">
    <xsl:template match="/">
        <xsl:element name="pidx:PipelineNominationCreate">
            <xsl:copy-of select="document('')/*/@xsi:schemaLocation"/>
like image 194
Mads Hansen Avatar answered Dec 23 '22 09:12

Mads Hansen


Have you tried adding/copying the xsi:schemaLocation attribute explicitely in the XSLT, like you would add/copy any other attribute? For example, after the line

<xsl:element name="pidx:PipelineNominationCreate">

try adding this:

<xsl:copy-of select="/node()/@*[local-name()='schemaLocation']"/>

This should copy any schemaLocation attributes (regardless of their namespace prefix) from the root node of the original document.

like image 39
O. R. Mapper Avatar answered Dec 23 '22 09:12

O. R. Mapper