2014-12-19 51 views
-3

如何选择所有具有id属性的元素?感谢如何使用xslt选择具有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> 
+0

请发布你的XML,试过xslt – Saurav 2014-12-19 08:27:00

+1

恐怕是一个非常无益的问题。您不会显示任何您试图使用的XLST代码,您的输入XML不完整并且因此不正确,您没有说明“选择”的含义,最后,您用XSLT 1.0和2.0标记了这个问题 - 这没有任何意义。 – 2014-12-19 16:29:21

回答

-2

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

*将匹配任何元素和[@id]谓词将允许只检索具有已经指定了一个“id”属性的元素。

+0

就像我看到的那样,我们不知道OP的意思是“选择具有'id'属性的元素”。 'apply-templates'本身并不以任何方式选择元素,只是将这些节点交给XSLT处理器并提示它找到这些元素的模板规则。也许OP意味着''? – 2014-12-19 16:32:23

相关问题