循环遍历xsl中的嵌套节点

时间:2014-10-31 09:53:08

标签: xml xslt

我正在尝试遍历XML文档中的一系列节点。当节点具有LeaveTypejfxpf:等前缀时,我可以找到节点xfa,但是当添加它们时,不会返回任何内容。

XML文件

<?xml version="1.0" encoding="UTF-8"?>
<?xfa generator="FF99V250_01"?>
<jfxpf:XPF xmlns:jfxpf="http://www.xfa.com/schema/xml-package">
    <jfxpf:Package>
        <jfxpf:Resource Location="Adoption_Leave_PT.xft">
            <jfxpf:Link ContentType="application/x-jetform-cft" />
        </jfxpf:Resource>
        <jfxpf:Resource Location="default.xml">
            <jfxpf:Content ContentType="text/xml" Location="default.xml">
                <xfa:Data xmlns:xfa="http://www.xfa.com/schema/xfa-data">
                    <xfa:DataGroup>
                        <Adoption_Leave_PT>
                            <?jetform ^Dat ^page Page1?>
                            <ENV />
                            <chkSetFullMand>0</chkSetFullMand>
                            <chkWFA>0</chkWFA>
                            <FFField1>Form Help</FFField1>
                            <chkHideMatDetails>1</chkHideMatDetails>
                            <optSelf>-1</optSelf>
                            <optManager>0</optManager>
                            <optAdmin>0</optAdmin>
                            <chkProtSomeInitiator>0</chkProtSomeInitiator>
                            <Department>Customer Services LGW</Department>
                            <chkProtInitiator>0</chkProtInitiator>
                            <chkProtManager>0</chkProtManager>
                            <CurrentWorkNo>01252554321</CurrentWorkNo>
                            <chkProtES>0</chkProtES>
                            <EmployeeStaffNo />
                            <EmployeeName />
                            <mandBirthDate>0</mandBirthDate>
                            <ManagerStaffNo>******</ManagerStaffNo>
                            <ManagerName>Not Required</ManagerName>
                            <chkProtPay>0</chkProtPay>
                            <txtEmployeeInfo>* Managers details can be overwritten if your manager is away from the business or you report to a different manager.</txtEmployeeInfo>
                            <chkShowLetter>0</chkShowLetter>
                            <chkFirstTime>1</chkFirstTime>
                            <chkLetterAmended>0</chkLetterAmended>
                            <LeaveType>Adoption</LeaveType>
                            <EMPSTAFFNO />
                            <chkMaternityChat>1</chkMaternityChat>
                            <EMPNAME />
                            <EMPFIRSTNAME />
                            <MGRSTAFFNO />
                            <txtLine1 />
                            <MGRNAME />
                            <txtMaternitySection>Adoption Details</txtMaternitySection>
                            <txtESMaternitySection>Admin Unit/ Employee Services Use Only</txtESMaternitySection>
                            <txtEWC>Expected Date child is to be placed with you :</txtEWC>
                            <EWC />
                            <DateHSMP />
                            <radPensionableYes>0</radPensionableYes>
                            <radPensionableNo>-1</radPensionableNo>
                            <txtPensionM>*</txtPensionM>
                            <txtPensionRepay>Would you like your pension contribution to be deducted</txtPensionRepay>
                            <radPensionRepay3>0</radPensionRepay3>
                            <txtPensionRepayM>*</txtPensionRepayM>
                            <radPensionRepay1>0</radPensionRepay1>
                            <txtIntentionToReturn>Intention to return to work (not binding)</txtIntentionToReturn>
                            <radReturnYes>0</radReturnYes>
                            <radReturnNo>-1</radReturnNo>
                            <txtIntentionToReturnM>*</txtIntentionToReturnM>
                            <txtAnticipatedReturnDate>Anticipated return to work date (not binding) :</txtAnticipatedReturnDate>
                            <AnticipatedReturnDate />
                            <MATB1Sent>0</MATB1Sent>
                            <txtMATB1SentM>*</txtMATB1SentM>
                            <JFWF_ACTION>Initiate</JFWF_ACTION>
                            <chkMATB1Seen>1</chkMATB1Seen>
                            <txtESSection>Admin Unit/ Employee Services Use Only</txtESSection>
                            <txtESTitle1>Setting up Adoption Leave</txtESTitle1>
                            <txtLine3 />
                            <txtESTitle2>On Return</txtESTitle2>
                            <chkESMATB1Received>0</chkESMATB1Received>
                            <chkESMATB1ReceivedM>*</chkESMATB1ReceivedM>
                            <txtConfirmedReturnDate>Confirmed Return Date :</txtConfirmedReturnDate>
                            <ConfirmedReturnDate />
                            <txtComments>Other Comments :</txtComments>
                            <Comments />
                            <txtPension>Pension :</txtPension>
                            <radNotApplicable>-1</radNotApplicable>
                            <radNotPensionable>0</radNotPensionable>
                            <rad3Months>0</rad3Months>
                            <radLumpSum>0</radLumpSum>
                            <txtPaySection>Pay Services Use Only</txtPaySection>
                            <txtPSTitle1>Setting up Adoption Pay</txtPSTitle1>
                            <txtLine4 />
                            <txtPSTitle2>Rework if needed</txtPSTitle2>
                            <txtLine5 />
                            <txtPSTitle3>On Return</txtPSTitle3>
                            <chkPSMATB1Received>0</chkPSMATB1Received>
                            <chkPSMATB1ReceivedM>*</chkPSMATB1ReceivedM>
                            <chkMaternityPayUpdated>0</chkMaternityPayUpdated>
                            <chkSMPtoNormal>0</chkSMPtoNormal>
                            <chkSMPtoNormalM>*</chkSMPtoNormalM>
                            <chkMaternityPayEntered>0</chkMaternityPayEntered>
                            <chkMaternityPayEnteredM>*</chkMaternityPayEnteredM>
                            <txtPSTitle2comment>(if required)</txtPSTitle2comment>
                            <JFWF_DEBUGACTOR />
                            <JFWF_DEBUGOPT />
                            <JFWF_AGENT />
                            <JFWF_DELEGATE />
                            <JFWF_CHOICE>Initiate</JFWF_CHOICE>
                            <JFWF_STATUS />
                            <JFWF_TRANSPORT>EMAIL</JFWF_TRANSPORT>
                            <JFWF_VERSION />
                            <txtEWCM>*</txtEWCM>
                            <txtBirthDate>Actual Placement Date of Child :</txtBirthDate>
                            <ActualBirthDate />
                            <ActualDateHSMP />
                            <chkDateChanges>0</chkDateChanges>
                            <DateWFA>01APR2007</DateWFA>
                            <txtDateUnpaid>Start Date for Unpaid Adoption Leave</txtDateUnpaid>
                            <DateUnpaid />
                            <txtActualDateUnpaid>Actual Start Date for Unpaid Adoption Leave</txtActualDateUnpaid>
                            <ActualDateUnpaid />
                            <txtESUpdatedOn />
                            <txtLine2 />
                            <txtPensionable>Do you wish Unpaid Adoption Leave to be pensionable (not binding) :</txtPensionable>
                            <txtAnticipatedReturnDateM>*</txtAnticipatedReturnDateM>
                            <txtMax>(Maximum 52 weeks)</txtMax>
                            <txtInfoAddress>After showing your evidential documents for Adoption to your manager, please write your Staff Number on them and send to :
                                Employee Services, Orient 3B, Waterside HAB3</txtInfoAddress>
                            <txtActualBirthDateM>*</txtActualBirthDateM>
                            <PAGENO>1</PAGENO>
                            <txtInfo2>If placement date of child is before the given Start Date for SAP, please change the Actual Start Date for SAP and send to Pay Services</txtInfo2>
                            <MGREMAIL />
                            <txtInfo1>The Start Date for Statutory Adoption Pay (start of adoption leave) MUST be on or before the Expected Date of Placement.</txtInfo1>
                            <LastMatDate />
                            <txtDateHSMP>Start Date for Statutory Adoption Pay</txtDateHSMP>
                            <txtDateHSMPM>*</txtDateHSMPM>
                            <txtActualDateHSMP>Actual Start Date for SAP</txtActualDateHSMP>
                            <?jetform ^Dat ^page Page2?>
                            <chkProtectLetter>0</chkProtectLetter>
                            <Address>Employee Services
                                Orient 3B, Waterside (HAB3)
                                British Airways Plc.
                                PO Box 365
                                Harmondsworth  
                                Middlesex  UB7 0GB</Address>
                            <chkWFA2>0</chkWFA2>
                            <LetterTelNo />
                            <LetterDate />
                            <LetterToName />
                            <LetterEWC />
                            <LetterLower>This means that you will receive Statutory Adoption Pay for the 26 weeks commencing</LetterLower>
                            <LetterHSMP />
                            <LetterAdditional>.  This will be followed immediately by 26 weeks</LetterAdditional>
                            <LetterUnpaid />
                            <LetterReturnDate />
                            <LetterFromName />
                            <Dept1>Employee Services</Dept1>
                        </Adoption_Leave_PT>
                    </xfa:DataGroup>
                </xfa:Data>
            </jfxpf:Content>
        </jfxpf:Resource>
    </jfxpf:Package>
</jfxpf:XPF>

XSL文件

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
    xmlns:jfxpf="http://www.xfa.com/schema/xml-package"    
    xmlns:xfa="http://www.xfa.com/schema/xfa-data"
>

<xsl:template match="/">
<xdp:xdp xmlns:xdp="http://ns.adobe.com/xdp/" timeStamp="2014-10-28T10:56:27Z" uuid="13c56b66-6ca8-4ae6-9ace-391f0a432ffe">
    <xfa:datasets xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/">
        <xfa:data>
            <AdoptionAndMaternityLeave>
                <SubmitURL/>
                <hiddenData>
                    <initiatedLevel>1</initiatedLevel>
                    <peopleLookupURL>http://www.aptosolutions.co.uk</peopleLookupURL>
                    <workSpaceURL>http://localhost:7002/workspace</workSpaceURL>
                    <fromMailingAdd>andrew.clowes@aptosolutions.co.uk</fromMailingAdd>
                    <dataCatcherURL>https://selfserve-uat.baplc.com/DataCatcher/localService.do</dataCatcherURL>
                    <versionData>APTO_DEV 1.00</versionData>
                    <devVersion>0.01</devVersion>
                    <formAssetURL>/Applications/Adoption and Maternity Leave/1.0/Forms/MaternityLeave.xdp</formAssetURL>
                    <letterSaved>0</letterSaved>
                </hiddenData>
                <xsl:for-each select="jfxpf:XPF/jfxpf:Package/jfxpf:Resource/jfxpf:Content/xfa:Data/xfa:DataGroup/Adoption_Leave_PT">
                    <FormName><xsl:value-of select="LeaveType"/></FormName>
                </xsl:for-each>
            </AdoptionAndMaternityLeave>
        </xfa:data>
    </xfa:datasets>
    <pdf xmlns="http://ns.adobe.com/xdp/pdf/" href="MaternityLeave.pdf"/>
    <xfdf xmlns="http://ns.adobe.com/xfdf/" xml:space="preserve">
        <annots/>
    </xfdf>
</xdp:xdp>
</xsl:template>
</xsl:stylesheet>

这是无效的代码块:

<xsl:for-each select="jfxpf:XPF/jfxpf:Package/jfxpf:Resource/jfxpf:Content/xfa:Data/xfa:DataGroup/Adoption_Leave_PT">
    <FormName><xsl:value-of select="LeaveType"/></FormName>
</xsl:for-each>

1 个答案:

答案 0 :(得分:1)

这里的问题是您正在重新定义xfa:前缀。选择另一个前缀来寻址源XML中的元素,例如:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:jfxpf="http://www.xfa.com/schema/xml-package"    
xmlns:ns0="http://www.xfa.com/schema/xfa-data">

然后:

<xsl:for-each select="jfxpf:XPF/jfxpf:Package/jfxpf:Resource/jfxpf:Content/ns0:Data/ns0:DataGroup/Adoption_Leave_PT">
    <FormName><xsl:value-of select="LeaveType"/></FormName>
</xsl:for-each>