xml - Preceding-sibling and following-sibling not working with additional element -


i first want apologize length of question, providing information help.

i attempting use single xsl on multiple xml documents, , works on original document (the text of 4 walls in room, each wall represented tei surfacegrp element). however, need modify xsl deal tei surfacegrp element, representing 2 sides of written page, , collection of pages.

my original xml code 4 walls this:

<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> 

that convert following 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> 

via 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> 

when run on new document surfacegrp element,

<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 son <hi rend="underline">thus</hi> nailed <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> 

i 1 page's worth of information. makes sense, because page fitting same surfacegrp slot wall in original code. when try modify code move collection of pages level

 <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> 

i same result. , have no idea why. don't understand preceding-sibling , following-sibling thought did, , if there's cleaner way accomplish want i'd happy use it.

i don't understand want achieve of code looks rather odd, instance want achieve with

    <xsl:variable name="total_blocks">         <xsl:value-of select="../last()"/>     </xsl:variable> 

? in general such constructs can written <xsl:variable name="total_blocks" select="../last()"/> expression ../last() return 1 long there parent node ...

another oddity count(../following-sibling::node()/position()) don't think more count(../following-sibling::node()).


Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

python - build a suggestions list using fuzzywuzzy -