xsl-list
[Top] [All Lists]

RE: [xsl] position of entry with respect to its row

2009-07-09 04:30:16
Consider:

select="parent::tgroup/descendant::entry[alignmark]/position()"

This evaluates parent::tgroup/descendant::entry[alignmark], and then for
each node in this sequence it returns the position of the node in that
sequence. So if there are five nodes in the sequence, the value of the
variable will be the sequence 1,2,3,4,5. It looks to me as if you are making
the common mistake of thinking that position() gives you the position of a
node within the sequence of its siblings. Define a function

<xsl:function name="f:sibling-position" as="xs:integer">
  <xsl:param name="node" as="element()"/>
  <xsl:sequence select="count($node/preceding-sibling::*)+1"/>
</xsl:function>

and then replace position() in your expression by f:sibling-position(.).

Regards,

Michael Kay
http://www.saxonica.com/
http://twitter.com/michaelhkay 

 

-----Original Message-----
From: Ganesh Babu N [mailto:nbabuganesh(_at_)gmail(_dot_)com] 
Sent: 09 July 2009 05:52
To: XSL
Subject: [xsl] position of entry with respect to its row

Dear All,

I am having following XML table:

<table frame="none">
       <label>Table 2</label>
       <caption>Sample for table alignmark.</caption>
       <tgroup cols="4">
               <colspec colnum="1" colname="col1" />
               <colspec colnum="2" colname="col2" />
               <colspec colnum="3" colname="col3" />
               <colspec colnum="4" colname="col4" />
               <thead>
                       <row>
                               <entry top="true" 
bottom="true">Variable</entry>
                               <entry align="center" top="true"
bottom="true">Mean
(<italic>Character alignment</italic>)</entry>
                               <entry align="center" top="true"
bottom="true">Median
(<bold>Alignmark</bold>)</entry>
                               <entry align="center" 
top="true" bottom="true">SD (<bold>Alignmark</bold>)</entry>
                       </row>
               </thead>
               <tbody>
                       <row>
                               <entry top="true">Salary</entry>
                               <entry align="char" char="&#x00B1;"
top="true">160&#x00B1;170</entry>
                               <entry top="true">10<alignmark 
/>.10</entry>
                               <entry top="true">a<alignmark 
/> bcde</entry>
                       </row>
                       <row>
                               <entry>Bonus</entry>
                               <entry align="char"
char="&#x00B1;">180&#x00B1;190</entry>
                               <entry>0<alignmark />.201</entry>
                               <entry>pq<alignmark />r stu</entry>
                       </row>
                       <row>
                               <entry>Optional Grants</entry>
                               <entry align="char"
char="&#x00B1;">100&#x00B1;110</entry>
                               <entry>1230<alignmark />.30</entry>
                               <entry>efg<alignmark /> hg</entry>
                       </row>
                       <row>
                               <entry>Stock return (%)</entry>
                               <entry align="char"
char="&#x00B1;">120&#x00B1;130</entry>
                               <entry>40<alignmark />.410</entry>
                               <entry><alignmark />df I</entry>
                       </row>
                       <row>
                               <entry>Standard return in (%) 
values</entry>
                               <entry align="char"
char="&#x00D7;">130&#x00D7;150</entry>
                               <entry>0<alignmark />.501</entry>
                               <entry>123</entry>
                       </row>
                       <row>
                               <entry>Age of CEO (years)</entry>
                               <entry align="char"
char="&#x00D7;">150&#x00D7;170</entry>
                               <entry>56<alignmark />.60</entry>
                               <entry>567</entry>
                       </row>
                       <row>
                               <entry bottom="true">SIC moves</entry>
                               <entry align="char" char="&#x00D7;"
bottom="true">170&#x00D7;180</entry>
                               <entry 
bottom="true">542<alignmark />.70</entry>
                               <entry bottom="true">789</entry>
                       </row>
               </tbody>
       </tgroup>
</table>


Note presence of alignmark tag. In which column this 
alignmark tag is present, the corresponding <colspec> should 
be changed to <tb:colspec>

I tried to take the position of the entry which is having 
alignmark tag but i am not getting it.

XSL Code:

<xsl:template match="colspec">
  <xsl:variable name="enpos"
select="parent::tgroup/descendant::entry[alignmark]/position()"/>
     <xsl:choose>
        <xsl:when test="position() = $enpos">
          <tb:colspec>
               <xsl:copy-of select="@*"/>
        </tb:colspec>
       </xsl:when>
       <xsl:otherwise>
           <colspec>
                 <xsl:copy-of select="@*"/>
           </colspec>
        </xsl:otherwise>
   </xsl:choose>
</xsl:template>

In the output the tb namespace has been added for all 
colspec. But it should apply only to 3rd and 4th colspec. 
Please suggest where i am going wrong.

Regards,
Ganesh

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>