2015-09-06 140 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

相关问题