如何使用xslt选择具有id属性的所有元素

时间:2014-12-19 08:25:04

标签: xml xslt xslt-1.0 xslt-2.0

如何选择具有id属性的所有元素?感谢

  <article docsubtype="rev" version="5.2" xml:lang="en" xmlns:ce="http://www.elsevier.com/xml/common/dtd" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:sb="http://www.elsevier.com/xml/common/struct-bib/dtd" xmlns:sa="http://www.elsevier.com/xml/common/struct-aff/dtd" xmlns:mml="http://www.w3.org/1998/Math/MathML">
        <item-info>
            <jid>APPET</jid>
            <aid>2303</aid>
            <ce:pii>S0195-6663(14)00474-7</ce:pii>
            <ce:doi>10.1016/j.appet.2014.10.004</ce:doi>
            <ce:copyright type="full-transfer" year="2014">Elsevier Ltd</ce:copyright>
            <ce:copyright-line>© 2014 Elsevier Ltd. All rights reserved.</ce:copyright-line><!--<x title="Appetite"/>--><!--<x issn="0195-6663"/>--><!--<x volume="&#x25A0;&#x25A0;"/>--><!--<x coverYear="2014"/>--><!--<x type="authorsRunningHead">E.M. Forman, M.L. Butryn</x>-->
        </item-info>
        <ce:floats>
            <ce:figure id="f0010">
                <ce:label>Fig. 1<!--<x>.&#x2002;</x>--></ce:label>
                <ce:caption id="ca0010">
                    <ce:simple-para id="sp0020">Conceptual model of weight gain and overweight.</ce:simple-para>
                </ce:caption>
                <ce:link id="ln0010" locator="appet2303-fig-0001"/>
            </ce:figure>
            <ce:table frame="topbot" id="t0010">
                <ce:label>Table 1<!--<x> </x>--></ce:label>
                <ce:caption id="ca0015">
                    <ce:simple-para id="sp0025">Commonalities of, and distinctions between, standard behavioral interventions and acceptance-based behavioral treatment.</ce:simple-para>
                </ce:caption>
                <tgroup cols="4">
                    <colspec colname="col1" colnum="1"/>
                    <colspec colname="col2" colnum="2"/>
                    <colspec colname="col3" colnum="3"/>
                    <colspec colname="col4" colnum="4"/>
                    <thead>
                        <row>
                            <entry>Domain</entry>
                            <entry>Example components common to both standard behavioral treatment and ABT</entry>
                            <entry>Example components unique to or more strongly emphasized in ABT</entry>
                            <entry>Example components unique to or more strongly emphasized in standard behavioral treatment</entry>
                        </row>
                    </thead>
                    <tbody>
                        <row>
                            <entry>Psychoeducation</entry>
                            <entry>
                                <ce:list id="ulist0015">
                                    <ce:list-item id="u0040">
                                        <ce:label>•<!--<x>&#x2002;</x>--></ce:label>
                                        <ce:para id="p0190">Nutritional information and guidelines regarding calorie intake</ce:para>
                                    </ce:list-item>
                                    <ce:list-item id="u0045">
                                        <ce:label>•<!--<x>&#x2002;</x>--></ce:label>
                                        <ce:para id="p0195">Additional tools for meeting dietary goals, such as limiting fat intake or portion control</ce:para>
                                    </ce:list-item>
                                    <ce:list-item id="u0050">
                                        <ce:label>•<!--<x>&#x2002;</x>--></ce:label>
                                        <ce:para id="p0200">Guidelines for physical activity</ce:para>
                                    </ce:list-item>
                                    <ce:list-item id="u0055">
                                        <ce:label>•<!--<x>&#x2002;</x>--></ce:label>
                                        <ce:para id="p0205">Obesogenic environment as a challenge to weight loss</ce:para>
                                    </ce:list-item>
                                </ce:list>
                            </entry>
                            <entry>
                                <ce:list id="ulist0020">
                                    <ce:list-item id="u0060">
                                        <ce:label>•<!--<x>&#x2002;</x>--></ce:label>
                                        <ce:para id="p0210">Psychoeducation relating to the mind's response to fatty, salty, sweet foods and exertion</ce:para>
                                    </ce:list-item>
                                    <ce:list-item id="u0065">
                                        <ce:label>•<!--<x>&#x2002;</x>--></ce:label>
                                        <ce:para id="p0215">The impossibility of fully controlling internal responses</ce:para>
                                    </ce:list-item>
                                </ce:list>
                            </entry>

1 个答案:

答案 0 :(得分:-2)

通常,它使用XPath,例如<xsl:apply-templates select="//*[@id]" />

*将匹配任何元素,[@id]谓词将仅允许检索具有&#34; id&#34;已指定的属性。