2016-02-12 85 views
0

因此,我在課堂上使用了這段XML文檔。XSLT - 屬於不屬於屬性的元素中的'a href'

<etymology>The <a href="https://en.wikipedia.org/wiki/Yakama">Yakama</a> Native American tribe</etymology> 

它在詞源的元素中包含href。當XSLT默認將其轉換時,鏈接將以僅文本顯示的方式「取消激活」,並且不再鏈接到其他頁面。

我需要知道在這裏做什麼:

<td width="25%"> 
    <xsl:value-of select="etymology"/> 
</td> 

這樣的鏈接多達有可能在詞源元素將翻譯或顯示爲一個鏈接,並沒有轉化成純文本。在樣式表中定義

我目前也是唯一的模板是這樣的:

<xsl:template match="/"> 

    <html> 
     <head> 
     <title>Washington Counties</title>   
     </head> 

     <body> 
     <h1>Washington Counties</h1> 
     <p> 
      (<a><xsl:attribute name="href"> 
       <xsl:value-of select="counties/@source" /> 
      </xsl:attribute> 
      data source</a>) 
     </p> 

     <table border="1" style="border-collapse: collapse;"> 

      <tr><th>County</th><th>INCITS</th><th>County Seat</th><th>Established</th><th>Origin</th><th>Etymology</th><th>Population</th><th>Area</th><th>Map</th> 
      </tr> 
      <xsl:for-each select="counties/county"> 
       <xsl:sort select="established" order="ascending" data-type="number" /> 
       <tr> 
       <td> 
        <xsl:choose> 
         <xsl:when test="name = 'Grays Harbor County'" > 
          <a> 
          <xsl:attribute name="href"> 
           <xsl:value-of select="@href" /> 
          </xsl:attribute> 
          <xsl:value-of select="name" /> 
          </a> 
          <sup><a href="#b">b</a></sup> 
         </xsl:when> 

         <xsl:when test="name = 'Mason County'" > 
          <a> 
          <xsl:attribute name="href"> 
           <xsl:value-of select="@href" /> 
          </xsl:attribute> 
          <xsl:value-of select="name" /> 
          </a> 
          <sup><a href="#c">c</a></sup> 
         </xsl:when> 

         <xsl:when test="name = 'Kitsap County'" > 
          <a> 
          <xsl:attribute name="href"> 
           <xsl:value-of select="@href" /> 
          </xsl:attribute> 
          <xsl:value-of select="name" /> 
          </a> 
          <sup><a href="#d">d</a></sup> 
         </xsl:when> 

         <xsl:when test="name = 'Clark County'" > 
          <a> 
          <xsl:attribute name="href"> 
           <xsl:value-of select="@href" /> 
          </xsl:attribute> 
          <xsl:value-of select="name" /> 
          </a> 
          <sup><a href="#e">e</a></sup> 
         </xsl:when> 

         <xsl:when test="name = 'Yakima County'" > 
          <a> 
          <xsl:attribute name="href"> 
           <xsl:value-of select="@href" /> 
          </xsl:attribute> 
          <xsl:value-of select="name" /> 
          </a> 
          <sup><a href="#f">f</a></sup> 
         </xsl:when> 

         <xsl:when test="name = 'Jefferson County'" > 
          <a> 
          <xsl:attribute name="href"> 
           <xsl:value-of select="@href" /> 
          </xsl:attribute> 
          <xsl:value-of select="name" /> 
          </a> 
          <sup><a href="#g">g</a></sup> 
         </xsl:when> 

         <xsl:when test="name = 'Clallam County'" > 
          <a> 
          <xsl:attribute name="href"> 
           <xsl:value-of select="@href" /> 
          </xsl:attribute> 
          <xsl:value-of select="name" /> 
          </a> 
          <sup><a href="#g">g</a></sup> 
         </xsl:when> 

         <xsl:otherwise> 
          <a> 
          <xsl:attribute name="href"> 
           <xsl:value-of select="@href" /> 
          </xsl:attribute> 
          <xsl:value-of select="name" /> 
          </a> 
         </xsl:otherwise> 
        </xsl:choose> 
       </td> 
       <td> 
        <a> 
        <xsl:attribute name="href"> 
         <xsl:value-of select="incits/@href" /> 
        </xsl:attribute> 
        <xsl:value-of select="incits" /></a> 
       </td> 
       <td> 
        <a> 
        <xsl:attribute name="href"> 
         <xsl:value-of select="countySeat/@href" /> 
        </xsl:attribute> 
        <xsl:value-of select="countySeat" /></a> 
       </td> 
       <td> 
        <xsl:choose> 
         <xsl:when test="established = 1879">  
          <xsl:value-of select="established" /> <sup> 
           <a href="#a">a</a> 
          </sup> 
         </xsl:when> 

         <xsl:otherwise> 
          <xsl:value-of select="established" /> 
         </xsl:otherwise> 
        </xsl:choose> 
       </td> 
       <td> 
       <xsl:choose> 
        <xsl:when test="origin != 0"> 
         <xsl:value-of select="origin" /> 
        </xsl:when> 
        <xsl:otherwise> 
         Original County 
        </xsl:otherwise> 
       </xsl:choose> 
       </td> 
       <td width="25%"> 
        <xsl:value-of select="etymology"/> 
       </td> 
       <td><xsl:value-of select="population" /></td> 
       <td><xsl:value-of select="area[@unit='mi2']" /> sq mi 
       <br />(<xsl:value-of select="area[@unit='km2']" /> sq km) 
       </td> 
       <td> 
       <img> 
        <xsl:attribute name="src"> 
         <xsl:value-of select="map/@src" /> 
        </xsl:attribute> 
        <xsl:attribute name="alt"> 
         <xsl:value-of select="./name" /> 
        </xsl:attribute> 
       </img> 
       </td> 
       </tr> 
      </xsl:for-each> 

     </table> 

     <br /> 
     <strong>Footnotes</strong> 
     <br /> 
     <xsl:for-each select="counties/footnote"> 
      <p> 
      <xsl:attribute name="id"> 
       <xsl:value-of select="@id" /> 
      </xsl:attribute> 
      <xsl:value-of select="@id" />. <xsl:value-of select="."/></p> 
     </xsl:for-each> 
     </body>  
    </html> 
</xsl:template> 

,最後的XML文件,我轉換: http://puu.sh/n4XiV.xml

+0

這是一個很好的例子,您爲什麼需要發佈[mcve],而不是脫離上下文。 –

+0

請在您的問題中發佈您的XML(最好是最小化)。 –

+0

我無法發佈XML文件,因爲它超過了30000個字符限制。 –

回答

1

xsl:value-of將一如它的名字說,只有走價值的節點。您需要使用xsl:apply-templates來處理器繼續處理內容。

由於默認操作是複製,您將在輸出中的標記內獲得所有內容。

0

相反的:

<xsl:value-of select="etymology"/> 

做:

<xsl:apply-templates select="etymology/node()"/> 

,並確保您有複製a和文本節點模板。

+0

通過模板,你的意思是我必須做一個新的在哪裏match將包含與'a'有關的東西?而且,對於參考鏈接中的文本來說有點類似? –

+0

@Invert_Tails如果不知道你已有的其他模板,我無法回答你的問題。這就是我對你的問題的評論。 –

+0

我已更新我的問題與相關的片段的文件和模板,我希望這可以幫助。 –