使用tei进行xml层次结构/ xsl处理:注意

时间:2014-06-09 15:52:00

标签: xml xslt xslt-2.0 tei

我希望这只是我无知的一种表现,而不是一个不可能的问题,但我不能让我的生活成功。

我正在使用TEI名称空间为XML编写脚注,相关数据打包如下:

<surface xml:id="EETS.T.29">
            <label>Verse 29</label>
            <graphic url="/Images/IMG_0479.JPG"/>
            <zone>
                <line>
                    <orig><hi>N</hi>ow in <damage>th</damage>e name of oure lord ihesus</orig>
                </line>
                <line>
                    <orig>of right hool herte <ex>&amp;</ex> in our<ex>e</ex>
                        <note place="bottom" anchored="true" xml:id="explanatory">Although “r” on the
                        painted panels of the chapel is consistently written with an otiose mark
                        when it concludes a word, the mark here is rendered more heavily and
                        with a dot indicating suspension above the r. This rendering as “oure”
                        is a linguistic outlier for the area based on the electronic <emph
                        rend="italic">Linguistic Atlas of Late Medieval English</emph>’s
                        linguistic profiles for “oure,” “our,” and “oure.” See eLALME's <ref
                        target="http://archive.ling.ed.ac.uk/ihd/elalme_scripts/mapping/user-defined_maps.html"
                        >User Defined Maps</ref> for more information. Unfortunately the current
                        online version does not allow direct linking between static dotmaps and
                        linguistic profiles.</note> best entent</orig>
                </line>
                <line>
                    <orig>our<ex>e</ex> lyf reme<ex>m</ex>bryng froward and vicious</orig>
                </line>
                <line>
                    <orig>ay contrarye to the comaundement</orig>
                </line>
                <line>
                    <orig>of crist ih<ex>es</ex>u now wyth avisement</orig>
                </line>
                <line>
                    <orig>the lord beseching <gap quantity="2" unit="chars" reason="illegible"
                        /><note place="bottom" anchored="true" xml:id="informational">Trapp
                        suggests "of" here, which fits the space in a way that MacCracken's "in
                        thyn" will not, but it does not seem to fit the admittedly paltry
                        remnants of the text. "In" seems the likely word here, but the text is
                        too damaged to definitively state that this is the case.</note>
                        <damage>mercy and pete</damage></orig>
                </line>
                <line>
                    <orig>our<ex>e</ex> youthe <ex>&amp;</ex> age that we have
                        <damage>myspent</damage></orig>
                </line>
                <line>
                    <orig>wyt<damage>h t</damage>h<damage>is woor</damage>d <damage>mercy
                        knelyng</damage> on oure kne<note place="bottom" anchored="true"
                        xml:id="informational">This change occurs only in the Clopton
                        verses.</note></orig>
                </line>
            </zone>
        </surface>

因为这是命名空间的一个新部分,所以我不能使用标准样式表,并编写了以下模板来对显示的文本块中的注释进行编号:

<xsl:template match="tei:note">
    <xsl:variable name="num">
        <xsl:number count="tei:note" level="any" from="/tei:TEI/tei:sourceDoc/tei:surfaceGrp/tei:surface"/>
    </xsl:variable>
    <xsl:variable name="panel_name">
        <xsl:value-of select="concat(../../../../@xml:id,$num)"/>
    </xsl:variable>
    <xsl:choose>
        <xsl:when test="@xml:id ='explanatory'">
            <span class="explanatory"><sup><a><xsl:attribute name="href"><xsl:value-of select="concat('#fn',$num)"/></xsl:attribute><xsl:attribute name="id"><xsl:value-of select="$panel_name"/></xsl:attribute><font size="-1"><xsl:value-of select="$num"/></font></a></sup></span>
        </xsl:when>
        <xsl:when test="@xml:id ='informational'">
            <span class="informational"><sup><a><xsl:attribute name="href"><xsl:value-of select="concat('#fn',$num)"/></xsl:attribute><xsl:attribute name="id"><xsl:value-of select="$panel_name"/></xsl:attribute><font size="-1"><xsl:value-of select="$num"/></font></a></sup></span>
        </xsl:when>
        <xsl:otherwise/>
    </xsl:choose>
</xsl:template>

然而,我的问题是使用以下一组模板,这些模板试图在页面底部显示注释的正文,编号如下:

        <xsl:template name="makeNotes">
            <xsl:variable name="num" select="count(.//tei:note)"/> 
            <xsl:variable name="panel_name">
                <xsl:value-of select="concat(@xml:id,$num)"/>
            </xsl:variable>

            <div class="notes">
                <div class="noteHeading">Notes</div>

                <xsl:call-template name="loop"> 
                    <xsl:with-param name="i" select="number(1)"/>
                    <xsl:with-param name="max" select="$num"/> 
                </xsl:call-template>
           </div>    
        </xsl:template>
   <xsl:template name="loop"> 
        <!--recursive loop until done--> 
        <xsl:param name="i"/> 
        <xsl:param name="max"/> 

        <xsl:for-each select=".//tei:orig">
            <xsl:if test="tei:note">
                <xsl:if test="$i &lt;= $max"> 
                    <!-- Repeated content Here --> 
                    <!-- use value-of i to get loop index --> 
                    <div class ="note"><span class="noteLabel"><xsl:attribute name="id"><xsl:value-of select="concat('fn',$i)"/></xsl:attribute><xsl:value-of select="$i"></xsl:value-of>.</span><div class="noteBody"><xsl:value-of select="tei:note"/></div></div>
                    <xsl:call-template name="loop"> 
                        <xsl:with-param name="i" select="$i + 1"/> 
                        <xsl:with-param name="max" select="$max"/> 
                    </xsl:call-template> 
                </xsl:if> 
            </xsl:if>
        </xsl:for-each>

我可以通过修改tei:note模板中的代码来格式化代码以正确显示数字,或者我可以格式化代码以正确显示注释,这就是我在这里所拥有的。我需要能够正确地显示音符和编号,并且我理解它不起作用的原因是tei:note仅在每行的层次结构中出现一次。我知道如何用过程语言来做,但是因为xsl是功能性的,所以我很难过,我见过的任何方法都没有(使用count()<xsl:number>等)。

我目前的输出如下:

<div class="note"><span class="noteLabel" id="fn1">1.</span>
    <div class="noteBody">Although "r" on the
      painted panels of the chapel is consistently written with an otiose mark
      when it concludes a word, the mark here is rendered more heavily and
      with a dot indicating suspension above the r. This rendering as "oure"
      is a linguistic outlier for the area based on the electronic Linguistic Atlas of Late Medieval English's
      linguistic profiles for "oure," "our," and "oure." See eLALME's User Defined Maps for more information. Unfortunately the current
      online version does not allow direct linking between static dotmaps and
      linguistic profiles.</div>
  </div>
  <div class="note"><span class="noteLabel" id="fn1">1.</span>
    <div class="noteBody">Trapp
      suggests "of" here, which fits the space in a way that MacCracken's "in
      thyn" will not, but it does not seem to fit the admittedly paltry
      remnants of the text. "In" seems the likely word here, but the text is
      too damaged to definitively state that this is the case.</div>
  </div>
  <div class="note"><span class="noteLabel" id="fn1">1.</span>
    <div class="noteBody">This change occurs only in the Clopton
      verses.</div>
  </div>

我需要的结果表明如下:

<div class="note"><span class="noteLabel" id="fn1">1.</span>
    <div class="noteBody">Although "r" on the
      painted panels of the chapel is consistently written with an otiose mark
      when it concludes a word, the mark here is rendered more heavily and
      with a dot indicating suspension above the r. This rendering as "oure"
      is a linguistic outlier for the area based on the electronic Linguistic Atlas of Late Medieval English's
      linguistic profiles for "oure," "our," and "oure." See eLALME's User Defined Maps for more information. Unfortunately the current
      online version does not allow direct linking between static dotmaps and
      linguistic profiles.</div>
  </div>
  <div class="note"><span class="noteLabel" id="fn2">2.</span>
    <div class="noteBody">Trapp
      suggests "of" here, which fits the space in a way that MacCracken's "in
      thyn" will not, but it does not seem to fit the admittedly paltry
      remnants of the text. "In" seems the likely word here, but the text is
      too damaged to definitively state that this is the case.</div>
  </div>
  <div class="note"><span class="noteLabel" id="fn3">3.</span>
    <div class="noteBody">This change occurs only in the Clopton
      verses.</div>
  </div>

1 个答案:

答案 0 :(得分:0)

我认为您需要的是一些代码如下(您需要调整模板以匹配命名空间中的元素,但因为您的示例没有显示我没有使用过的命名空间):

<xsl:stylesheet version="2.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="html" indent="yes"/>

<xsl:template match="surface">
  <xsl:apply-templates select=".//orig[note]" mode="list"/>
</xsl:template>

<xsl:template match="orig" mode="list">
<div class ="note"><span class="noteLabel" id="fn{position()}"><xsl:value-of select="position()"></xsl:value-of>.</span><div class="noteBody"><xsl:value-of select="note"/></div></div>
</xsl:template>

</xsl:stylesheet>

将您发布的输入样本转换为结果

<div class="note"><span class="noteLabel" id="fn1">1.</span><div class="noteBody">Although “r” on the
      painted panels of the chapel is consistently written with an otiose mark
      when it concludes a word, the mark here is rendered more heavily and
      with a dot indicating suspension above the r. This rendering as “oure”
      is a linguistic outlier for the area based on the electronic Linguistic Atlas of Late
      Medieval English’s
      linguistic profiles for “oure,” “our,” and “oure.” See eLALME's User Defined Maps
      for more information. Unfortunately the current
      online version does not allow direct linking between static dotmaps and
      linguistic profiles.
   </div>
</div>
<div class="note"><span class="noteLabel" id="fn2">2.</span><div class="noteBody">Trapp
      suggests "of" here, which fits the space in a way that MacCracken's "in
      thyn" will not, but it does not seem to fit the admittedly paltry
      remnants of the text. "In" seems the likely word here, but the text is
      too damaged to definitively state that this is the case.
   </div>
</div>
<div class="note"><span class="noteLabel" id="fn3">3.</span><div class="noteBody">This change occurs only in the Clopton
      verses.
   </div>
</div>

如果我正确理解了这个问题,这是我对XSLT部分的建议。由于目标格式似乎是HTML,我不知道为什么你不使用有序列表和列表项来为项目编号。