[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

[xsl] changing colspec based on entry property


Subject: [xsl] changing colspec based on entry property
From: Ganesh Babu N <nbabuganesh@xxxxxxxxx>
Date: Tue, 7 Jul 2009 17:06:31 +0530

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


Current Thread
Keywords