xsl using variable on a node
I have the following XML
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="RichGrid.xslt"?>
<root>
<meta>
<Table1_row>
<feqnum width="360" visibility="hidden" contentEditable="false" />
<feqt1 width="450" visibility="" contentEditable="true" />
</Table1_row>
</meta>
<Tables>
<Table1_row>
<feqnum>ME5598</feqnum>
<feqt1>22.8</feqt1>
</Table1_row>
<Table1_row>
<feqnum>ME6624</feqnum>
<feqt1>55.9</feqt1>
</Table1_row>
</Tables>
</root>
while doing XSLT translation I want to derive style from meta root.
I'm using following XSL -
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:key name="tableData" match="root/Tables/*" use="local-name()"/>
<xsl:key name="metaData" match="root/meta/*" use="name()"/>
<xsl:template match="/">
<body>
<xsl:apply-templates select="root/Tables/*[generate-id() = generate-id(key('tableData', local-name())[1])]"/>
</body>
</xsl:template>
<xsl:template match="*">
<table border="1" style="width:650px;border-collapse:collapse;">
<thead bgcolor="silver">
<xsl:for-each select="key('tableData', local-name())[1]/*">
<th width="50px"><xsl:value-of select="name()"/></th>
</xsl:for-each>
</thead>
<xsl:apply-templates select="key('tableData', local-name())" mode="content"/>
</table>
</xsl:template>
<xsl:template match="*" mode="content">
<tr OriginalRow="true">
<xsl:for-each select="*">
<td>
<span>
<xsl:variable name="curNode" select= "concat('//meta//', name(current()), '/@contentEditable')" />
<xsl:attribute name="style">
<xsl:apply-templates select="//meta//*" mode="style"/>OVERFLOW:hidden;
</xsl:attribute>
<xsl:attribute name="ContentEditable">
<xsl:value-of select="$curNode" />
</xsl:attribute>
<xsl:value-of select="."/>
</span>
</td>
</xsl:for-each>
</tr>
</xsl:template>
<xsl:template match="*" mode="style">
<xsl:for-each select="@*">
<xsl:value-of select="name()"/>:<xsl:value-of select="."/>;
</xsl:for-each>
</xsl:template>
<xsl:template match="*" mode="edit">
<xsl:value-of select="."/>;
</xsl:template>
</xsl:stylesheet>
Instead of getting the value of the node, the name of the node is getting generated. Here is the output HTML
<TABLE style="WIDTH: 650px; BORDER-COLLAPSE: collapse" border=1>
<THEAD bgColor=silver>
<TH width=50>feqnum</TH>
<TH width=50>feqt1</TH>
</THEAD>
<TBODY>
<TR OriginalRow="true">
<TD><SPAN contentEditable=//meta//feqnum/@contentEditable style="OVERFLOW: hidden; WIDTH: 450px; contentEditable: true">ME5598</SPAN></TD>
<TD><SPAN contentEditable=//meta//feqt1/@contentEditable
style="OVERFLOW: hidden; WIDTH: 450px; contentEditable: true">22.8</SPAN></TD></TR>
<TR OriginalRow="true">
<TD><SPAN contentEditable=//meta//feqnum/@contentEditable
style="OVERFLOW: hidden; WIDTH: 450px; contentEditable: true">ME6624</SPAN></TD>
<TD><SPAN contentEditable=//meta//feqt1/@contentEditable
style="OVERFLOW: hidden; WIDTH: 450px; contentEditable: true">55.9</SPAN></TD></TR></TBODY></TABLE>
You help will be much appreciated. I have spent almost 2 days around the bush.
|