1

この質問が長くなってしまったことをまずお詫びしたいと思いますが、この情報が役に立てば幸いです。

複数の xml ドキュメントで単一の xsl を使用しようとしていますが、元のドキュメント (各壁が TEI surfaceGrp 要素として表される、部屋の 4 つの壁のテキスト) で機能します。ただし、今度は xsl を変更して、書かれたページの両面とページのコレクションを表す追加の TEI surfaceGrp 要素を処理する必要があります。

4 つの壁の元の 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 &gt; 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 &gt; 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>

1ページ分の情報しか得られません。ページは元のコードで壁が行うのと同じ 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 &gt; 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 &gt; 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>

同じ結果が得られます。そして、私には理由がわかりません。私は明らかに、私が思っていたように、先行兄弟と後続兄弟を理解していません。私が望むことを達成するためのよりクリーンな方法があれば、喜んでそれを使用します。

4

1 に答える 1