randomvoice
randomvoice

Reputation: 1

Xsl adding elements to output that are not in input

As an example, consider the following xsl:

<?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:ext="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2"
    xmlns:puf="urn:pagero:ExtensionComponent:1.0"
    xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2">

    <xsl:template match="/">
        <Invoice xmlns:cac="urn:pagero:CommonAggregateComponents:1.0"
                  xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"
                  xmlns:puf="urn:pagero:ExtensionComponent:1.0"
                  xmlns:ext="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2"
                  xmlns="urn:pagero:PageroUniversalFormat:Invoice:1.0">
            <cbc:CustomizationID>urn:pagero.com:puf:billing:2.0</cbc:CustomizationID>
            <cbc:ProfileID>urn:pagero.com:puf:billing:1.0</cbc:ProfileID>
            <!-->xsl:copy-of select="."/ -->
            <!-- xsl:apply-templates select="@* | node()[not(self::cbc:UBLVersionID)]"/-->
            <!--xsl:copy-of select="Invoice"/-->
            <xsl:apply-templates select="Invoice"/>
        </Invoice>
    </xsl:template>

    <xsl:template match="Invoice">
        <xsl:copy>
            <xsl:apply-templates select="node()[not(self::cbc:UBLVersionID)]"/>
        </xsl:copy>
    </xsl:template>


    <!-- Suppress the cbc:UBLVersionID element -->
    <xsl:template match="cbc:UBLVersionID"/>

    <!-- Copy elements and attributes as-is -->
    <xsl:template match="@* | node()">
        <xsl:copy>
            <xsl:apply-templates select="@* | node()"/>
        </xsl:copy>
    </xsl:template>


</xsl:stylesheet>

given the following xml 'snippet' of an UBL Invoice xml Document

<Invoice xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2" xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">
<cbc:UBLVersionID>2.1</cbc:UBLVersionID>
<cbc:ID>TOSL108</cbc:ID>
<cbc:IssueDate>2009-12-15</cbc:IssueDate>
<cbc:InvoiceTypeCode listID="UN/ECE 1001 Subset" listAgencyID="6">380</cbc:InvoiceTypeCode>
<cbc:Note languageID="en">Ordered in our booth at the convention.</cbc:Note>
<cbc:TaxPointDate>2009-11-30</cbc:TaxPointDate>
<cbc:DocumentCurrencyCode listID="ISO 4217 Alpha" listAgencyID="6">EUR</cbc:DocumentCurrencyCode>
<cbc:AccountingCost>Project cost code 123</cbc:AccountingCost>
<cac:InvoicePeriod>
<cbc:StartDate>2009-11-01</cbc:StartDate>
<cbc:EndDate>2009-11-30</cbc:EndDate>
</cac:InvoicePeriod>
<cac:OrderReference>
<cbc:ID>123</cbc:ID>
</cac:OrderReference>
<cac:ContractDocumentReference>
<cbc:ID>Contract321</cbc:ID>
<cbc:DocumentType>Framework agreement</cbc:DocumentType>
</cac:ContractDocumentReference>
<cac:AdditionalDocumentReference>
<cbc:ID>Doc1</cbc:ID>
<cbc:DocumentType>Timesheet</cbc:DocumentType>
<cac:Attachment>
<cac:ExternalReference>
<cbc:URI>http://www.suppliersite.eu/sheet001.html</cbc:URI>
</cac:ExternalReference>
</cac:Attachment>
</cac:AdditionalDocumentReference>
<cac:AdditionalDocumentReference>
<cbc:ID>Doc2</cbc:ID>
<cbc:DocumentType>Drawing</cbc:DocumentType>
<cac:Attachment>
<cbc:EmbeddedDocumentBinaryObject mimeCode="application/pdf">UjBsR09EbGhjZ0dTQUxNQUFBUUNBRU1tQ1p0dU1GUXhEUzhi</cbc:EmbeddedDocumentBinaryObject>
</cac:Attachment>
</cac:AdditionalDocumentReference>
</Invoice>

You can compare against the expected output:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<Invoice xmlns:cac="urn:pagero:CommonAggregateComponents:1.0"
    xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"
    xmlns:puf="urn:pagero:ExtensionComponent:1.0"
    xmlns:ext="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2"
    xmlns="urn:pagero:PageroUniversalFormat:Invoice:1.0">
    <cbc:CustomizationID>urn:pagero.com:puf:billing:2.0</cbc:CustomizationID>
    <cbc:ProfileID>urn:pagero.com:puf:billing:1.0</cbc:ProfileID>
    <cbc:ID>123456</cbc:ID>
    <cbc:IssueDate>2018-01-01</cbc:IssueDate>
    <cbc:IssueTime>21:32:52</cbc:IssueTime>
    <cbc:DueDate>2018-12-01</cbc:DueDate>
    <cbc:InvoiceTypeCode>380</cbc:InvoiceTypeCode>
    <cbc:Note>Header Text 1</cbc:Note>
    <cbc:Note>Header Text 2</cbc:Note>
    <cbc:Note>Header Text 3</cbc:Note>
    <cbc:TaxPointDate>2017-01-01</cbc:TaxPointDate>
    <cbc:DocumentCurrencyCode>EUR</cbc:DocumentCurrencyCode>
    <cbc:TaxCurrencyCode>USD</cbc:TaxCurrencyCode>
    <cbc:AccountingCost>Accounting Cost</cbc:AccountingCost>
    <cbc:BuyerReference>Buyer Reference</cbc:BuyerReference>
    <cac:InvoicePeriod>
        <cbc:StartDate>2018-01-01</cbc:StartDate>
        <cbc:EndDate>2018-12-31</cbc:EndDate>
        <cbc:Description>Period description</cbc:Description>
    </cac:InvoicePeriod>
    <cac:OrderReference>
        <cbc:ID>PO Number</cbc:ID>
        <cbc:SalesOrderID>Sales Order number</cbc:SalesOrderID>
        <cbc:IssueDate>2018-12-01</cbc:IssueDate>
    </cac:OrderReference>
    <cac:DespatchDocumentReference>
        <cbc:ID>Despatch Document ID</cbc:ID>
        <cbc:IssueDate>2018-12-01</cbc:IssueDate>
    </cac:DespatchDocumentReference>
    <cac:ReceiptDocumentReference>
        <cbc:ID>Receipt ID</cbc:ID>
    </cac:ReceiptDocumentReference>
    <cac:OriginatorDocumentReference>
        <cbc:ID>Tender Reference ID</cbc:ID>
        <cbc:IssueDate>2018-01-01</cbc:IssueDate>
    </cac:OriginatorDocumentReference>
    <cac:ContractDocumentReference>
        <cbc:ID>Contract Reference ID</cbc:ID>
        <cbc:IssueDate>2018-12-01</cbc:IssueDate>
    </cac:ContractDocumentReference>
    <cac:ProjectReference>
        <cbc:ID>Project Reference ID</cbc:ID>
    </cac:ProjectReference>
    <cac:AdditionalDocumentReference>
        <cbc:ID>123456</cbc:ID>
        <cbc:DocumentDescription>Timesheet</cbc:DocumentDescription>
        <cac:Attachment>
            <cbc:EmbeddedDocumentBinaryObject mimeCode="application/pdf" filename="timesheet.pdf">JVBER=</cbc:EmbeddedDocumentBinaryObject>
        </cac:Attachment>
    </cac:AdditionalDocumentReference>
</Invoice>

But for some reason, although it's present in the xsl, the cbc:CustomizationID and cbc:ProfileID are not being output.

I have tried isolating the templates and using xsl:copy and even just xsl:element with xsl:value-of and nothing has worked.

This was associated with a similar question but I reviewed that question and it does not answer my question. My question is specifically why the given xsl does not emit the included elements cbc:ProfileID and cbc:CustomizationID although namespace was provided for both.

Upvotes: 0

Views: 25

Answers (0)

Related Questions