Как создать верхний и нижний колонтитулы в коде XSLT ниже приведен пример

#xslt

#xslt

Вопрос:

 Input XML:
<?xml version="1.0" encoding="UTF-8"?>
<EmployeeImport>
    <Employee>
        <XRefCode>1234</XRefCode>
        <EmployeeNumber>789</EmployeeNumber>
        <Title/>
        <FirstName>France</FirstName>
        <MiddleName/>
        <LastName>Intern</LastName>
        <WorkAssignment>
            <JobXrefCode>7925</JobXrefCode>
            <DeptXrefCode>DEFAULT</DeptXrefCode>
        </WorkAssignment>
        <EmploymentStatus>
            <PayClassXrefCode>Full Time</PayClassXrefCode>
            <PayTypeXrefCode>MONTHLY</PayTypeXrefCode>
            <EmploymentStatusXrefCode>Active</EmploymentStatusXrefCode>
        </EmploymentStatus>
        <EmployeeProperty>
            <XrefCode>EmployeePropertyXrefCode1</XrefCode>
        </EmployeeProperty>
        <EmployeeProperty>
            <XrefCode>EmployeePropertyXrefCode2</XrefCode>
        </EmployeeProperty>
        <AddressInformation>
            <ContactInformationTypeXrefCode>PrimaryResidence</ContactInformationTypeXrefCode>
            <EffectiveStart>2020-07-17</EffectiveStart>
            <Address1/>
            <Address2>123</Address2>
        </AddressInformation>
        <EmployeeMaritalStatus>
            <MaritalStatusXrefCode>MARRIED</MaritalStatusXrefCode>
        </EmployeeMaritalStatus>
    </Employee>
</EmployeeImport>

Output XML:
<?xml version="1.0" encoding="UTF-8"?>
<Employee>
    <Employee_XRefCode>1234</Employee_XRefCode>
    <Employee_EmployeeNumber>789</Employee_EmployeeNumber>
    <Employee_Title/>
    <Employee_FirstName>France</Employee_FirstName>
    <Employee_MiddleName/>
    <Employee_LastName>Intern</Employee_LastName>
    <Employee_WorkAssignment_JobXrefCode>7925</Employee_WorkAssignment_JobXrefCode>
    <Employee_WorkAssignment_DeptXrefCode>DEFAULT</Employee_WorkAssignment_DeptXrefCode>
    <Employee_EmploymentStatus_PayClassXrefCode>Full Time</Employee_EmploymentStatus_PayClassXrefCode>
    <Employee_EmploymentStatus_PayTypeXrefCode>MONTHLY</Employee_EmploymentStatus_PayTypeXrefCode>
  

<Employee_EmploymentStatus_EmploymentStatusXrefCode>Active</Employee_EmploymentStatus_EmploymentStatusXrefCode>
<Employee_EmployeeProperty_XrefCode>employeeproperty_xrefcode1</Employee_EmployeeProperty_XrefCode>
<Employee_EmployeeProperty_XrefCode>employeeproperty_xrefcode2</Employee_EmployeeProperty_XrefCode>
<Employee_AddressInformation_ContactInformationTypeXrefCode>PrimaryResidence</Employee_AddressInformation_ContactInformationTypeXrefCode>
<Employee_AddressInformation_EffectiveStart>2020-07-17</Employee_AddressInformation_EffectiveStart>
<Employee_AddressInformation_Address1/>
<Employee_AddressInformation_Address2>123</Employee_AddressInformation_Address2>
<Employee_EmployeeMaritalStatus_MaritalStatusXrefCode>MARRIED</Employee_EmployeeMaritalStatus_MaritalStatusXrefCode>

Ответ №1:

Используйте приведенный ниже код

     <xsl:template match="EmployeeImport">
    <xsl:copy>
        <xsl:for-each select="Employee//*[not(*)]">
            <xsl:variable name="elementname">
                <xsl:value-of select="ancestor-or-self::*[ancestor-or-self::Employee]/local-name()" separator="_"/>
            </xsl:variable>
            <xsl:element name="{$elementname}"><xsl:value-of select="."/></xsl:element>
        </xsl:for-each>
    </xsl:copy>
</xsl:template>
  

Смотрите преобразование наhttps://xsltfiddle .liberty-development.net/6pS2B76