Re: [xsl] Following-sibling - question

Subject: Re: [xsl] Following-sibling - question
From: "a kusa akusa8@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 6 Jan 2016 18:02:06 -0000
Sorry about the input XML. The numbers actually don't mean anything.
It can be any content.  The input would be something like:

<table>

   <tbody>
      <row>
         <entry>Some content here</entry>
         <entry>Some content here</entry>
      </row>
      <row>
         <entry>New entry</entry>
         <entry>Some content here</entry>
         <entry>Some content here</entry>
      </row>
      <row>
         <entry>Some content here</entry>
         <entry>New entry</entry>
         <entry>Some content here</entry>
      </row>
      <row>
         <entry>Some content here</entry>
         <entry>Some content here</entry>
         <entry>New entry</entry>
         <entry>Some content here</entry>
      </row>
      <row>
         <entry>Some content here</entry>
      </row>
   </tbody>


</table>


Thank you for your reply David. I get an idea now on how to proceed.


On Wed, Jan 6, 2016 at 9:16 AM, David Carlisle d.p.carlisle@xxxxxxxxx
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:
>
> Your suggested input is not well formed, and one of the entries changes from
> 2 to 4  and no indication is given about where teh extra entry is added, in
> your example it is added in position 1,2,4 is this powers of 2?
>
> anyway the following  adds the element in positions 1,2,3 producing the
> following once the input is made well formed.
>
> <table>
>
>    <tbody>
>       <row>
>          <entry>1</entry>
>          <entry>2</entry>
>       </row>
>       <row>
>          <entry>Added</entry>
>          <entry>3</entry>
>          <entry>2</entry>
>       </row>
>       <row>
>          <entry>4</entry>
>          <entry>Added</entry>
>          <entry>2</entry>
>       </row>
>       <row>
>          <entry>5</entry>
>          <entry>2</entry>
>          <entry>Added</entry>
>          <entry>2</entry>
>       </row>
>       <row>
>          <entry>6</entry>
>       </row>
>    </tbody>
>
>
> </table>
>
>
> David
>
> <xsl:stylesheet version="2.0"
>         xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
>
>  <xsl:strip-space elements="tbody row"/>
>
>  <xsl:param name="n" select="3"/>
>
>  <xsl:output indent="yes"/>
>
>  <xsl:template match="*|node()">
>   <xsl:copy>
>    <xsl:apply-templates/>
>   </xsl:copy>
>  </xsl:template>
>
>  <xsl:template match="row">
>   <xsl:copy>
>    <xsl:variable name="r" select="position()"/>
>    <xsl:apply-templates select="entry">
>     <xsl:with-param name="r" select="$r"/>
>    </xsl:apply-templates>
>   </xsl:copy></xsl:template>
>
>  <xsl:template match="entry">
>   <xsl:param name="r"/>
>   <xsl:variable name="e" select="position()"/>
>   <xsl:if test="$r - 2 lt $n and $e =  $r - 1">
>     <entry>Added</entry>
>   </xsl:if>
>   <xsl:copy-of select="."/>
>  </xsl:template>
>
>
>
> </xsl:stylesheet>
>
> XSL-List info and archive
> EasyUnsubscribe (by email)

Current Thread