1

我有一个 XSL 脚本,它读取 XML 文件以获取元素中的值,创建另一个 XML 以供下游使用。

原始 XML 文件的输出示例如下:

<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>

我的 XSL 脚本有代码来引用一些值,它看起来像这样:

<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"/>

它适用于除“位置代码”之外的所有内容,唯一的区别是位置之前有一个特殊元素<e:UDF name="FRB_5fOnboarding_5fLocation">。有谁知道如何映射到位置代码或者我如何编写一个程序来获取原始 XML 文件,删除所有出现的<e:UDF name="FRB_5fOnboarding_5fLocation">元素,并输出一个看起来与第一个相同的新 XML 文件,除了不需要的元素.

4

1 回答 1

1

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"/>
于 2013-03-05T22:43:41.783 回答