1

I have a file like:

<?xml version='1.0' encoding='UTF-8'?>
<wd:Report_Data xmlns:wd="urn:com.workday.report/Business_Process_Transactions_-_Canceled__Rescinded_or_Corrected">
   <wd:Report_Entry>
       <wd:Worker wd:Descriptor="**** *****">
           <wd:ID wd:type="WID">2b994449ed3b10ba7bc5d65f971ba4d4</wd:ID>
           <wd:ID wd:type="Employee_ID">00083646</wd:ID>
       </wd:Worker>
   </wd:Report_Entry>
</wd:Report_Data>

I use this xslt to transform it:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"             
        xmlns:wd="urn:com.workday.report/Business_Process_Transactions_-_Canceled__Rescinded_or_Corrected"
                    exclude-result-prefixes="wd">

        <xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>


        <xsl:template match ="/">
            <xsl:apply-templates select="wd:Report_Data/wd:Report_Entry/wd:Worker[@wd:Descriptor!='']" />
        </xsl:template>


        <xsl:template match="wd:Report_Data/wd:Report_Entry/wd:Worker[@wd:Descriptor!='']">
            <wd:Instance_Reference>
                <wd:ID>
                    <xsl:attribute name="wd:type">
                        <xsl:value-of select="wd:ID[@wd:type='Contingent_Worker_ID' or @wd:type='Employee_ID']/@wd:type"/>
                    </xsl:attribute>

                    <xsl:value-of select="wd:ID[@wd:type='Contingent_Worker_ID' or @wd:type='Employee_ID']"></xsl:value-of>
                </wd:ID>
            </wd:Instance_Reference>
        </xsl:template>

    </xsl:stylesheet>

It gives me:

<wd:Instance_Reference xmlns:wd="urn:com.workday.report/Business_Process_Transactions_-_Canceled__Rescinded_or_Corrected">
    <wd:ID wd:type="Employee_ID">00083646</wd:ID>
</wd:Instance_Reference>

I would like to have this element removed:

xmlns:wd="urn:com.workday.report/Business_Process_Transactions_-_Canceled__Rescinded_or_Corrected"

pshemek
  • 1,369
  • 4
  • 17
  • 33
  • That's not an element, that's a namespace declaration. If you remove, it you must also remove the `wd:` prefix; you cannot use a prefix without binding it to a namespace. – michael.hor257k Jun 30 '16 at 11:32

1 Answers1

1

You cant have prefixes without a namespace declaration. But if you the namespace remove and be left with an output like this...

<Instance_Reference>
    <ID type="Employee_ID">00083646</ID>
</Instance_Reference>

then all you need do is to create the output elements without exclude the prefixes. In your example, just chnage the final templa to this..

<xsl:template match="wd:Report_Data/wd:Report_Entry/wd:Worker[@wd:Descriptor!='']">
        <Instance_Reference>
            <ID>
                <xsl:attribute name="type">
                    <xsl:value-of select="wd:ID[@wd:type='Contingent_Worker_ID' or @wd:type='Employee_ID']/@wd:type"/>
                </xsl:attribute>

                <xsl:value-of select="wd:ID[@wd:type='Contingent_Worker_ID' or @wd:type='Employee_ID']"></xsl:value-of>
            </ID>
        </Instance_Reference>
    </xsl:template>
Phil Blackburn
  • 1,047
  • 1
  • 8
  • 13