2015-09-06 31 views
1

我有一小段XML,我正在創建一個列表樣式,出於某種原因,我的一個模板match =「ref」 ,樣式ref元素,但忽略xsl:attribute後面的apply-templates調用。所以ref元素的所有孩子都沒有得到風格。<xsl:apply-templates>不適用於<xsl:attribute>之後的子項

我的XML是在這裏:

<list> 
<item>London, British Library Harley 2251: <ref 
     target="Quis_Dabit/British_Library_Harley_2251/British_Library_Harley_2251_f42v.html" 
      ><orig xmlns="http://www.tei-c.org/ns/1.0">To se my joye · my hertis higħ 
      plesaunce</orig></ref></item> 
<item>London, British Library Harley 2255: <ref 
     target="Quis_Dabit/British_Library_Harley_2255/British_Library_Harley_2255_f67r.html" 
      ><orig xmlns="http://www.tei-c.org/ns/1.0">to see my Joye/myn hertys hiħ 
      plesaunce</orig></ref></item> 
<item>Cambridge, Jesus College Q.G.8: 
    <ref target="Quis_Dabit/Jesus_College_Q_G_8/Jesus_Q_G_8_f20r.html"> 
     <orig xmlns="http://www.tei-c.org/ns/1.0"><hi rend="touched">T</hi>o see my ioye my 
       hart<ex>is </ex>high <hi rend="underline">plesauncce</hi>. </orig></ref></item> 
<item>Oxford, Bodleian Library Laud 683: <ref target="Quis_Dabit/Laud_683/Laud_683_f78r.html" 
      ><orig xmlns="http://www.tei-c.org/ns/1.0">to se mẏ joie/mẏn hertis hiħ 
      plesaunce</orig></ref></item> 
<item>Oxford, St. John's College 56: <ref target="Quis_Dabit/St_John_56/St_John_56_73v.html" 
      ><orig xmlns="http://www.tei-c.org/ns/1.0">To see my ioye/myne hertis hygh 
      plesaunce ؛</orig></ref></item></list> 

和我的XSL是如下,點在哪裏,事情就不幹工作註釋:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:xs="http://www.w3.org/2001/XMLSchema" 
exclude-result-prefixes="xs" 
version="1.0"> 
<xsl:output method="html" encoding="UTF-8"/> 

<xsl:template match="node()|@*"> 
    <xsl:copy> 
     <xsl:apply-templates/> 
    </xsl:copy> 
</xsl:template> 

<xsl:template match="list"> 
     <ul> 
      <xsl:apply-templates/> 
     </ul> 
</xsl:template> 

<xsl:template match="item"> 
    <li> 
     <xsl:apply-templates/> 
    </li> 
</xsl:template> 

<!--from here down it just stops working for no good reason that I know of--> 
<xsl:template match="ref"> 
    <a> 
     <xsl:attribute name="href"> 
      <xsl:value-of select="@target"/> 
     </xsl:attribute> 
     <xsl:apply-templates/> 
    </a> 
</xsl:template> 

<xsl:template match="orig"> 
    <span> 
     <xsl:apply-templates/> 
    </span> 
</xsl:template> 

<xsl:template match="hi"> 
    <xsl:choose> 
     <xsl:when test="@rend='touched'"> 
      <span class="touched"> 
       <xsl:apply-templates/> 
      </span> 
     </xsl:when> 
     <xsl:otherwise> 
      <span class="capital"> 
       <xsl:apply-templates/> 
      </span> 
     </xsl:otherwise> 
    </xsl:choose> 
</xsl:template> 

<xsl:template match="ex"> 
    <i> 
     <xsl:apply-templates></xsl:apply-templates> 
    </i> 
</xsl:template> 

我真的不知所措,因爲我寫了其他模板做類似的事情,他們在那裏工作得很好。

回答

2

其實你的match="ref"模板工作得很好。問題在於應該處理ref子元素的其他模板。請注意,示例XML中的orig元素位於名稱空間中。需要聲明引用該命名空間前綴:

<xsl:stylesheet ..... 
xmlns:ns="http://www.tei-c.org/ns/1.0" 
exclude-result-prefixes="xs ns" 
....> 

,然後使用該前綴命名空間中的元素相匹配:

<xsl:template match="ns:orig"> 
    <span> 
     <xsl:apply-templates/> 
    </span> 
</xsl:template> 
+0

感謝。我在我的主要xslt中有名稱空間,但是這只是爲了這個列表,我忘了包含它。 – medievalmatt

相關問題