我首先要为这个问题的长度道歉,但希望提供这些信息会有所帮助。
我试图在多个xml文档上使用单个xsl,它适用于我的原始文档(房间中四面墙的文本,每个墙表示为TEI surfaceGrp元素)。但是,现在我需要修改xsl来处理额外的TEI surfaceGrp元素,表示书面页面的两面,然后是页面集合。
我对四面墙的原始xml代码是这样的:
<TEI>
<sourceDoc>
<surfaceGrp xml:id="wall" n="South Wall">
<surface xml:id="EETS.T.29">
<label>Verse 29</label>
<graphic url="sw_test_1.jpg"/>
<zone>
<line/>
</zone>
</surface>
<surface xml:id="EETS.T.30">
<label>Verse 30</label>
<graphic url="sw_test_2.jpg"/>
<zone>
<line/>
</zone>
</surface>
<surface xml:id="EETS.T.27">
<label>Verse 27</label>
<graphic url="sw_test_3.jpg"/>
<zone>
<line/>
</zone>
</surface>
<surface xml:id="EETS.T.56">
<label>Verse 56</label>
<graphic url="sw_test_4.jpg"/>
<zone>
<line/>
</zone>
</surface>
<surface xml:id="EETS.T.57">
<label>Verse 57</label>
<graphic url="sw_test_5.jpg"/>
<zone>
<line/>
</zone>
</surface>
<surface xml:id="EETS.T.58">
<label>Verse 58</label>
<graphic url="sw_test_6.jpg"/>
<zone>
<line/>
</zone>
</surface>
<surface xml:id="EETS.T.59">
<label>Verse 59</label>
<graphic url="sw_test_7.jpg"/>
<zone>
<line/>
</zone>
</surface>
</surfaceGrp>
<surfaceGrp xml:id="wall" n="West Wall">
<surface xml:id="EETS.T.60">
<label>Verse 60</label>
<graphic url="ww_test_1.jpg"/>
<zone>
<line/>
</zone>
</surface>
<surface xml:id="EETS.T.63">
<label>Verse 63</label>
<graphic url="ww_test_2.jpg"/>
<zone>
<line/>
</zone>
</surface>
</surfaceGrp>
</sourceDoc>
我转换为以下html
<h1 class="menuHeader">
<span class="menuitem" id="image_thumbnail">
<a class="nav_link" href="sw_test_1-thumbnail.html">
<img class="thumbnail" src="../../Testament/Clopton/Thumbnails/sw_test_1-thumbnail.jpg"
alt="Verse 29"/>
</a>
</span>
<span class="menuitem" id="image_thumbnail">
<a class="nav_link" href="sw_test_2-thumbnail.html">
<img class="thumbnail" src="../../Testament/Clopton/Thumbnails/sw_test_2-thumbnail.jpg"
alt="Verse 30"/>
</a>
</span>
<span class="menuitem" id="image_thumbnail">
<a class="nav_link" href="sw_test_3-thumbnail.html">
<img class="thumbnail" src="../../Testament/Clopton/Thumbnails/sw_test_3-thumbnail.jpg"
alt="Verse 27"/>
</a>
</span>
<span class="menuitem" id="image_thumbnail">
<a class="nav_link" href="sw_test_4-thumbnail.html">
<img class="thumbnail" src="../../Testament/Clopton/Thumbnails/sw_test_4-thumbnail.jpg"
alt="Verse 56"/>
</a>
</span>
<span class="menuitem" id="image_thumbnail">
<a class="nav_link" href="sw_test_5-thumbnail.html">
<img class="thumbnail" src="../../Testament/Clopton/Thumbnails/sw_test_5-thumbnail.jpg"
alt="Verse 57"/>
</a>
</span>
<span class="menuitem" id="image_thumbnail">
<a class="nav_link" href="sw_test_6-thumbnail.html">
<img class="thumbnail" src="../../Testament/Clopton/Thumbnails/sw_test_6-thumbnail.jpg"
alt="Verse 58"/>
</a>
</span>
<span class="menuitem" id="image_thumbnail">
<a class="nav_link" href="sw_test_7-thumbnail.html">
<img class="thumbnail" src="../../Testament/Clopton/Thumbnails/sw_test_7-thumbnail.jpg"
alt="Verse 59"/>
</a>
</span>
<span class="menuitem" id="previousItem">
<a class="nav_link" href="sw_test_6.html"> Previous</a>
</span>
<span class="menuitem" id="nextItem">
<a class="nav_link" href="ww_test_1.html">Next</a>
</span>
通过这个xsl:
<xsl:template name="menuHeader">
<xsl:variable name="filename_length" select="string-length(tei:graphic/@url)"/>
<h1 class="menuHeader">
<span class="menuitem" id="groupLabel">
<xsl:choose>
<xsl:when test="../../../../tei:teiHeader/fileDesc/SourceDesc='Clopton_Chantry_Chapel'">
<xsl:value-of select="../@n"/>
<xsl:text> </xsl:text>
<span id="modelViewer">
<a href="../../Model/three/examples/chantry_chapel.html">
<xsl:text>(View Model)</xsl:text>
</a>
</span>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat(../@xml:id,' ',@n)"/>
</xsl:otherwise>
</xsl:choose>
</span>
<xsl:apply-templates select=".././/tei:graphic" mode="list"/>
<xsl:variable name="last_block" as="xs:integer">
<xsl:value-of select="count(../preceding-sibling::tei:surfaceGrp)"/>
</xsl:variable>
<xsl:variable name="next_block" as="xs:integer">
<xsl:value-of select="count(../following-sibling::tei:surfaceGrp)"/>
</xsl:variable>
<xsl:variable name="total_blocks">
<xsl:value-of select="../last()"/>
</xsl:variable>
<xsl:variable name="group_position" as="xs:integer">
<xsl:value-of
select="../../count(tei:surfaceGrp) - count(../following-sibling::node()/position())"
/>
</xsl:variable>
<xsl:variable name="last_item_id">
<xsl:value-of select="../../tei:surfaceGrp[last()]/tei:surface[last()]/@xml:id"/>
</xsl:variable>
<xsl:choose>
<xsl:when test="count(preceding-sibling::tei:surface)+1 > 1">
<span class="menuitem" id="previousItem">
<a class="nav_link">
<xsl:attribute name="href">
<xsl:value-of select="concat(substring(preceding-sibling::*[1]/tei:graphic/@url,1,($filename_length - 4)),'.html')"/>
</xsl:attribute>
Previous</a>
</span>
</xsl:when>
<xsl:when test="count(../preceding-sibling::tei:surfaceGrp)+1 > 1">
<span class="menuitem" id="previousItem">
<a class="nav_link"><xsl:attribute name="href">
<xsl:value-of select="concat(substring(../../tei:surfaceGrp[$last_block]/tei:surface[last()]/tei:graphic/@url,1,($filename_length - 4)),'.html')"/>
</xsl:attribute>Previous</a>
</span>
</xsl:when>
<xsl:otherwise>
<span class="menuitem" id="previousItem">
<a class="nav_link">Previous</a>
</span>
</xsl:otherwise>
</xsl:choose>
<xsl:choose>
<xsl:when test="$last_item_id = @xml:id">
<span class="menuitem" id="nextItem">
<a class="nav_link">Next</a>
</span>
</xsl:when>
<xsl:when test="position() = last()">
<span class="menuitem" id="nextItem">
<a class="nav_link"><xsl:attribute name="href"><xsl:value-of
select="concat(substring(../../tei:surfaceGrp[$group_position+1]/tei:surface[1]/tei:graphic/@url,1,($filename_length - 4)),'.html')"
/></xsl:attribute>Next</a>
</span>
</xsl:when>
<xsl:when test="not(position() = last())">
<span class="menuitem" id="nextItem">
<a class="nav_link"><xsl:attribute name="href"><xsl:value-of
select="concat(substring(following-sibling::*[1]/tei:graphic/@url,1,($filename_length - 4)),'.html')"
/></xsl:attribute>Next</a>
</span>
</xsl:when>
<xsl:otherwise/>
</xsl:choose>
</h1>
</xsl:template>
<xsl:template match="tei:graphic" mode="list">
<span class="menuitem" id="image_thumbnail">
<a class="nav_link">
<xsl:attribute name="href">
<xsl:value-of select="concat(substring(@url,1,string-length(@url)-4),'.html')"/>
</xsl:attribute>
<img class="thumbnail">
<xsl:attribute name="src">
<xsl:value-of
select="concat('../../',$title_folder,'/',$witness,'/',$thumbnail_folder,'/',substring(@url,1,string-length(@url)-4),'-thumbnail.jpg')"
/>
</xsl:attribute>
<xsl:attribute name="alt">
<xsl:value-of select="../tei:label"/>
</xsl:attribute>
</img>
</a>
</span>
</xsl:template>
当我在带有额外surfaceGrp元素的新文档上运行它时,
<TEI>
<sourceDoc>
<surfaceGrp xml:id="g.3" n="gathering">
<surfaceGrp xml:id="f.19" n="folio">
<surface n="verso">
<graphic url="Jesus_Q_G_8_f19v.jpg"/>
<zone n="EETS.QD.I">
<line/>
</zone>
<zone n="EETS.QD.1">
<line/>
</zone>
</surface>
</surfaceGrp>
<surfaceGrp xml:id="f.20" n="folio">
<surface n="recto">
<graphic url="Jesus_Q_G_8_f20r.jpg"/>
<zone n="EETS.QD.1">
<line/>
</zone>
<zone n="EETS.QD.2">
<line/>
</zone>
<zone n="EETS.QD.3">
<line/>
</zone>
<zone n="EETS.QD.4">
<line/>
</zone>
</surface>
<surface n="verso">
<graphic url="Jesus_Q_G_8_f20v.jpg"/>
<zone n="EETS.QD.4">
<line>
<orig>To see my son <hi rend="underline">thus</hi> nailed to <hi
rend="underline">a tre</hi> .</orig>
</line>
</zone>
<zone n="EETS.QD.5">
<line/>
</zone>
<zone n="EETS.QD.6">
<line/>
</zone>
<zone n="EETS.QD.7">
<line/>
</zone>
</surface>
</surfaceGrp>
</surfaceGrp>
</sourceDoc>
我只获得一页的信息。这是有道理的,因为页面适合墙壁在原始代码中执行的相同surfaceGrp插槽。但是当我尝试修改代码以升级到页面集合
时 <xsl:template name="menuHeader">
<xsl:variable name="filename_length" select="string-length(tei:graphic/@url)"/>
<h1 class="menuHeader">
<span class="menuitem" id="groupLabel">
<xsl:choose>
<xsl:when test="../../../../tei:teiHeader/fileDesc/SourceDesc='Clopton_Chantry_Chapel'">
<xsl:value-of select="../@n"/>
<xsl:text> </xsl:text>
<span id="modelViewer">
<a href="../../Model/three/examples/chantry_chapel.html">
<xsl:text>(View Model)</xsl:text>
</a>
</span>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat(../@xml:id,' ',@n)"/>
</xsl:otherwise>
</xsl:choose>
</span>
<xsl:apply-templates select=".././/tei:graphic" mode="list"/>
<xsl:variable name="last_block" as="xs:integer">
<xsl:choose>
<xsl:when test="../../../../tei:teiHeader/fileDesc/SourceDesc='Clopton_Chantry_Chapel'">
<xsl:value-of select="count(../preceding-sibling::tei:surfaceGrp)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="count(../../preceding-sibling::tei:surfaceGrp)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="next_block" as="xs:integer">
<xsl:choose>
<xsl:when test="../../../../tei:teiHeader/fileDesc/SourceDesc='Clopton_Chantry_Chapel'">
<xsl:value-of select="count(../following-sibling::tei:surfaceGrp)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="count(../../following-sibling::tei:surfaceGrp)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="total_blocks">
<xsl:value-of select="../last()"/>
</xsl:variable>
<xsl:variable name="group_position" as="xs:integer">
<xsl:choose>
<xsl:when test="../../../../tei:teiHeader/fileDesc/SourceDesc='Clopton_Chantry_Chapel'">
<xsl:value-of
select="../../count(tei:surfaceGrp) - count(../following-sibling::node()/position())"
/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of
select="../../../count(tei:surfaceGrp) - count(../following-sibling::node()/position())"
/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="last_item_id">
<xsl:choose>
<xsl:when test="../../../../tei:teiHeader/fileDesc/SourceDesc='Clopton_Chantry_Chapel'">
<xsl:value-of select="../../tei:surfaceGrp[last()]/tei:surface[last()]/@xml:id"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="../../../tei:surfaceGrp[last()]/tei:surfaceGrp[last()]/tei:surface[last()]/@xml:id"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:choose>
<xsl:when test="count(preceding-sibling::tei:surface)+1 > 1">
<span class="menuitem" id="previousItem">
<a class="nav_link">
<xsl:attribute name="href">
<xsl:value-of select="concat(substring(preceding-sibling::*[1]/tei:graphic/@url,1,($filename_length - 4)),'.html')"/>
</xsl:attribute>
Previous</a>
</span>
</xsl:when>
<xsl:when test="count(../preceding-sibling::tei:surfaceGrp)+1 > 1">
<span class="menuitem" id="previousItem">
<a class="nav_link"><xsl:attribute name="href">
<xsl:value-of select="concat(substring(../../tei:surfaceGrp[$last_block]/tei:surface[last()]/tei:graphic/@url,1,($filename_length - 4)),'.html')"/>
</xsl:attribute>Previous</a>
</span>
</xsl:when>
<xsl:otherwise>
<span class="menuitem" id="previousItem">
<a class="nav_link">Previous</a>
</span>
</xsl:otherwise>
</xsl:choose>
<xsl:choose>
<xsl:when test="$last_item_id = @xml:id">
<span class="menuitem" id="nextItem">
<a class="nav_link">Next</a>
</span>
</xsl:when>
<xsl:when test="position() = last()">
<span class="menuitem" id="nextItem">
<a class="nav_link"><xsl:attribute name="href"><xsl:value-of
select="concat(substring(../../tei:surfaceGrp[$group_position+1]/tei:surface[1]/tei:graphic/@url,1,($filename_length - 4)),'.html')"
/></xsl:attribute>Next</a>
</span>
</xsl:when>
<xsl:when test="not(position() = last())">
<span class="menuitem" id="nextItem">
<a class="nav_link"><xsl:attribute name="href"><xsl:value-of
select="concat(substring(following-sibling::*[1]/tei:graphic/@url,1,($filename_length - 4)),'.html')"
/></xsl:attribute>Next</a>
</span>
</xsl:when>
<xsl:otherwise/>
</xsl:choose>
</h1>
</xsl:template>
我得到了相同的结果。我不明白为什么。我显然不明白前兄弟和后兄弟以及我以为我做过,如果有更清洁的方法来实现我想要的东西,我会乐意使用它。
答案 0 :(得分:0)
我不明白你想要实现什么,但你的一些代码看起来很奇怪,例如你想用
实现什么? <xsl:variable name="total_blocks">
<xsl:value-of select="../last()"/>
</xsl:variable>
?通常,此类构造可以写为<xsl:variable name="total_blocks" select="../last()"/>
,但只要有父节点../last()
,表达式1
就会返回..
。
另一个奇怪的是count(../following-sibling::node()/position())
,我认为这不仅仅是count(../following-sibling::node())
。