2015-06-03 38 views
0

我有以下XML指定節點的接入孫子,XSLT:

<doc> 
    <table type="Horizontal lines" width="100%"> 
      <group cols="5"> 
       <colspec colname="1" colwidth="58%"/> 
       <colspec colname="2" colwidth="32%"/> 

       <thead> 
        <row> 
         <entry namest="1" align="center"> 
         <p type="Table head">Testing Table</p> 
         </entry> 
         <entry namest="2" align="center"> 
         <p type="Table head">Testing Head</p> 
         </entry> 
        </row> 
       </thead> 
       <tbody> 
        <row> 
         <entry namest="1" align="left"> 
         <p type="Table text">Mobile OS</p> 
         </entry> 
         <entry namest="2" align="left"> 
         <p type="Table text">Android</p> 
         </entry> 
        </row> 
        <row> 
         <entry namest="4" align="left"> 
         <p type="Table text"> 
          <link type="Hyperlink">www.facebook.com</link> 
         </p> 
         <p type="Table text"/> 
         </entry> 
         <entry namest="4" align="left"> 
         <p type="Table text"> 
          <link type="Hyperlink">www.skynews.com</link> 
         </p> 
         <p type="Table text"/> 
         </entry> 
        </row> 
      </tbody> 
     </group> 
    </table> 
    <para> 
     <entry namest="4" align="left"> 
     <p type="Table text"> 
      <link type="Hyperlink">www.devandroid.com</link> 
     </p> 
      <p type="Table text"> 
      <link type="Hyperlink">www.google.com</link> 
     </p> 
     <p type="Table text"/> 
     </entry> 
    </para> 
<doc> 

,你可以看到有文檔中的某些<link>節點放置<table>節點和孫子和一些<link>節點都出了<table>節點(與<table>節點沒有關係。 什麼,我需要做的就是簡單地轉換<link>節點文本(這是地方爲<table>節點的孫子的)到大寫字母。 (在這個例子中,只有<link type="Hyperlink">www.facebook.com</link> and <link type="Hyperlink">www.skynews.com</link>應該大寫。)

那麼,我怎樣才能只選擇<link>只在<table>節點內的節點呢?

我嘗試了一些代碼如下,但它沒有給出結果。

<xsl:template match="table::link"> 
     <xsl:copy> 
      <xsl:copy-of select="@*"/> 
      more codes... 
     </xsl:copy> 
</xsl:template> 

任何建議如何訪問孫節點的表節點?

+1

使用XPath'表// link' –

+0

@ JoelM.Lamsen 。有用。謝謝。 :) – sanjay

回答

0

您可以使用鏈接下面的比賽模式,在表格(鏈接的缺省模板規則將有一個較低的優先級):

<xsl:template match="link[ancestor::table]"> 
    ... 
</xsl:template> 

<xsl:template match="link"> 
    ... 
</xsl:template>