Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 20th, 2006, 08:14 AM
Registered User
 
Join Date: Jun 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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.

 
Old June 22nd, 2006, 12:20 PM
Authorized User
 
Join Date: May 2006
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default

But you are telling it to print the name: name(current())

<xsl:variable name="curNode" select= "concat('//meta//', current(), '/@contentEditable')" />

will just give you the value, but wouldn't you in fact want the name?

Brandon





Similar Threads
Thread Thread Starter Forum Replies Last Post
The reference node is not a child of this node.XSL XMLUser XSLT 2 February 25th, 2008 05:22 AM
ASSIGNING A JAVA SCRIPT VARIABLE TO A XSL VARIABLE SOMANATHAN10 XSLT 1 February 21st, 2007 04:26 AM
xsl:variable holding name of an xsl:param perissos XSLT 0 December 5th, 2006 07:09 AM
The difference between xsl:variable and xsl:param NEO1976 XML 2 July 24th, 2006 06:05 AM
constructing node-set content to xsl:variable MrWay XSLT 3 February 28th, 2006 10:39 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.