xml - Tricky XSL Problem -- Determining Position in Complex Array -


        <row>              <cell>phrase 1</cell> #0                 <check shuffle="false">                     <option key="1"/> #1                     <option key="0"/> #2                     <option key="0"/> #3                     <option key="0"/> #4                     <option key="0"/> #5                     <option key="0"/> #6                 </check>                 <cell>phrase 2</cell> #7                 <cell>phrase 3</cell> #8                 <check shuffle="false">                     <option key="1"/> #9                     <option key="0"/> #10                     <option key="0"/> #11                     <option key="0"/> #12                     <option key="0"/> #13                     <option key="0"/> #14                 </check>             </row> 

i've got following quandary.

i need find "index" in "row" tag both cells , each option.

how do in xsl? each cell counts 1 , each "option" children tags in siblings count. i've labeled "indexes" retrieve. realize there 1 way determining index of "cell" versus "option" element.

i know bit xsl enough in trouble , quite frustrated. appreciated.

thanks so!

use xsl:number:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform">     <xsl:template match="node()|@*" name="identity">         <xsl:copy>             <xsl:apply-templates select="node()|@*"/>         </xsl:copy>     </xsl:template>     <xsl:template match="cell|option">         <xsl:call-template name="identity"/>         <xsl:variable name="vposition">             <xsl:number count="cell|option" level="any" from="row" />         </xsl:variable>         <xsl:value-of select="$vposition - 1"/>     </xsl:template> </xsl:stylesheet> 

with input (more rows):

<table>     <row>         <cell>phrase 1</cell> #0                          <check shuffle="false">             <option key="1"/> #1                                  <option key="0"/> #2                                  <option key="0"/> #3                                  <option key="0"/> #4                                  <option key="0"/> #5                                  <option key="0"/> #6                          </check>         <cell>phrase 2</cell> #7                          <cell>phrase 3</cell> #8                          <check shuffle="false">             <option key="1"/> #9                                  <option key="0"/> #10                                  <option key="0"/> #11                                  <option key="0"/> #12                                  <option key="0"/> #13                                  <option key="0"/> #14                          </check>     </row>     <row>         <cell>phrase 1</cell> #0         <check shuffle="false">             <option key="1"/> #1             <option key="0"/> #2             <option key="0"/> #3         </check>         <cell>phrase 2</cell> #4         <check shuffle="false">             <option key="1"/> #5             <option key="0"/> #6         </check>         <cell>phrase 3</cell> #7     </row> </table> 

output:

<table>     <row>         <cell>phrase 1</cell>0 #0                          <check shuffle="false">             <option key="1"></option>1 #1                                  <option key="0"></option>2 #2                                  <option key="0"></option>3 #3                                  <option key="0"></option>4 #4                                  <option key="0"></option>5 #5                                  <option key="0"></option>6 #6                          </check>         <cell>phrase 2</cell>7 #7                          <cell>phrase 3</cell>8 #8                          <check shuffle="false">             <option key="1"></option>9 #9                                  <option key="0"></option>10 #10                                  <option key="0"></option>11 #11                                  <option key="0"></option>12 #12                                  <option key="0"></option>13 #13                                  <option key="0"></option>14 #14                          </check>     </row>     <row>         <cell>phrase 1</cell>0 #0         <check shuffle="false">             <option key="1"></option>1 #1             <option key="0"></option>2 #2             <option key="0"></option>3 #3         </check>         <cell>phrase 2</cell>4 #4         <check shuffle="false">             <option key="1"></option>5 #5             <option key="0"></option>6 #6         </check>         <cell>phrase 3</cell>7 #7     </row> </table> 

Comments