0

我正在使用 xpath 从 xhtml / xml 文件中获取一些节点名称。

我目前有这个 xpath: /xhtml:html/xhtml:head/xforms:model/xforms:instance/form/*[starts-with(local-name(), 'section')]

这将获得名称如下的节点:section-1_s1_partners section-2-s2_strategy

上述 xpath 的结果是匹配的节点,但我想为每个匹配获取完整节点名称。当我使用 name() 函数 name(/xhtml:html/xhtml:head/xforms:model/xforms:instance/form/*[starts-with(local-name(), 'section')]) 时,它只返回第一个匹配项,否则我不知道该怎么做..

有什么好主意吗??

谢谢!

(xhtml/xml:)

<xhtml:html ....>
 <xhtml:head>
     <xhtml:title>ASD-1</xhtml:title>
    <xforms:model id="fr-form-model">
        <xforms:instance id="fr-form-instance">
            <form>
                <section-1_s1_partners>
                    <control-304/>
                    <toggleForm>ASD</toggleForm>
                    <applicationid/>
                    <section-345>
                        <s1_kbPaAAr/>
                        <s1_kbDCCent/>
                        <s1_kbRAE/>
                    </section-345>
                    <section-s1_depDDFentGFress>
                        <address_search/>
                        <address_postcode/>
                        <address_address1/>
                        <address_address2/>
                        <address_address3/>
                        <address_city/>
                    </section-s1_departmentAddress>
                    <section-344>
                        <s1_companyPartner/>
                        <s1_companyRegistrationNumber/>
                        <s1_companyType/>
                        <s1_companySize/>
                    </section-344>
                    <section-s1_companyAddress>
                        <address_search/>
                        <address_postcode/>
                        <address_address1/>
                        <address_address2/>
                        <address_address3/>
                        <address_city/>
                    </section-s1_companyAddress>
                    <section-324>
                        <s1_plannedDate/>
                        <s1_workDescription/>
                        <s1_publicDescription/>
                        <s1_numberOfAssociates>1</s1_numberOfAssociates>
                        <s1_duration/>
                        <s1b_resubmissionYesNo/>
                        <s1_GAAGrogramNumber/>
                    </section-324>
                </section-1_s1_partners>
                <section-2-s2_strategy>
                    <control-4/>
                    <s2_memo_strategic/>
                    <s2_memo_problems/>
                    <s2_companyPosition/>
                    <s2_companyContribution/>
                    <s2_lackExpertise/>
                    <s2_essential/>
                    <s2_companySponsor/>
                    <s2_seekKnowledge/>
                    <s2_challenge/>
                </section-2-s2_strategy>
4

1 回答 1

0

name函数需要一个参数,它不能接受节点列表。您必须以您使用的语言迭代节点列表。例如,在xsh中:

for /xhtml:html/xhtml:head/xforms:model/xforms:instance/form/*[starts-with(local-name(), 'section')] 
    echo name()
于 2013-05-02T08:15:30.427 回答