Jeff
Jeff

Reputation: 11

Use XSL to remove XML element

I have an XSL script that reads an XML file to get the values within elements create another XML to be used downstream.

An example of the output from the original XML file is:

<e:OnboardingProcess>
    <e:Assignment>
        <e:Assignment>
            <e:Application>
                <e:Application>
                    <e:CandidateIndentificationNo>7047961</e:CandidateIndentificationNo>
                </e:Application>
            </e:Application>
            <e:Offer>
                <e:Offer>
                    <e:UDFs>
                        <e:UDF name="FRB_5fOnboarding_5fLocation">
                            <e:CustomSelectionElement>
                                <e:Code>1204</e:Code>
                            </e:CustomSelectionElement>
                        </e:UDF>
                    </e:UDFs>
                </e:Offer>
            </e:Offer>
            <e:TalentMasterFile>
                <e:TalentMasterFile>
                    <e:User>
                        <e:User>
                            <e:EmployeeID></e:EmployeeID>
                            <e:FirstName>Peter</e:FirstName>
                            <e:LastName>Griffin</e:LastName>
                        </e:User>
                    </e:User>
                </e:TalentMasterFile>
            </e:TalentMasterFile>

My XSL script has code to reference some of the values and it looks like this:

<xsl:variable name="CandidateNumber" select="../../e:Assignment/e:Assignment/e:Application/e:Application/e:CandidateIndentificationNo"/>
<xsl:variable name="FirstName" select="../../e:Assignment/e:Assignment/e:TalentMasterFile/e:TalentMasterFile/e:User/e:User/e:FirstName"/>
<xsl:variable name="LastName" select="../../e:Assignment/e:Assignment/e:TalentMasterFile/e:TalentMasterFile/e:User/e:User/e:LastName"/>
<xsl:variable name="Location" select="../../e:Assignment/e:Assignment/e:Offer/e:Offer/e:UDFs/e:CustomSelectionElement/e:Code"/>

It works great for everything except the "Location Code" and the only difference is the location has a special element before it <e:UDF name="FRB_5fOnboarding_5fLocation">. Does anybody know how to map down to the location code or how I just write a program to take the original XML file, remove all occurrences of the <e:UDF name="FRB_5fOnboarding_5fLocation"> element, and output a new XML file that looks identical to the first one except without the unwanted elements.

Upvotes: 1

Views: 175

Answers (1)

David Heijl
David Heijl

Reputation: 399

Your XPath to the location element is missing the e:UDF element step.

<xsl:variable name="Location" select="../../e:Assignment/e:Assignment/e:Offer/e:Offer/e:UDFs/e:CustomSelectionElement/e:Code"/>

should actually be

<xsl:variable name="Location" select="../../e:Assignment/e:Assignment/e:Offer/e:Offer/e:UDFs/e:UDF/e:CustomSelectionElement/e:Code"/>

Upvotes: 1

Related Questions