Click to See Complete Forum and Search --> : XSLT Variables question


r0k3t
05-13-2009, 11:47 AM
Hi there,

As I have mentioned before I am new to XSLT... It's super cool but takes a little learning. At any rate I am having a problem using a variable I created.

inside a foreach loop I have this.
<xsl:variable name="width" select="w:tcPr/w:tcW/@w:w" />

if I do this
<xsl:value-of select="$width"/>

I can see it prints just fine, I am clearly getting the value... but I am wanting to do this.
<td style="border: solid 1px silver; width: {$width}px;">

That doesn't work - even if I try to print it all I see is the literal text {$width} printed in the HTML that the XSLT creates.

I have researched this all over the place and read many times that all you need to do is place the variable name in curly brackets... What am I missing.

Thanks!

Charles
05-13-2009, 12:23 PM
It should work but since it doesn't try this nifty work around:<td>
<xsl:attribute name="style">
<xsl:text>border: solid 1px silver; width: </xsl:text>
<xsl:value-of select="$width"/>
<xsl:text>px</xsl:text>
</xsl:attribute>
</td>

r0k3t
05-13-2009, 01:41 PM
Hi there, thanks for the quick response...

I don't know - this is really frustrating. I know the style is getting applied cause if I change the border color it works, I know the number is there in the variable cause I can print it but when I try to use that number to change the size of the <td> element is doesn't work... It should in theory make the cells HUGE cause I am grabbing the EMU number from the MS office XML file (which would need to be converted if I can ever get this to work)

Here is the exact code. (minus the comments I just added)


<td>
<xsl:attribute name="style">
<xsl:text>border: solid 1px #fff0c0; width: </xsl:text>
<xsl:value-of select="$width"/>
<xsl:text>px;</xsl:text> << I tried removing the ; doesn't change anything
</xsl:attribute>
<xsl:value-of select="$width"/> <<<< This shows me the variable is working.
<xsl:value-of select="w:p/w:r/w:t"/>
</td>



Again - thanks for your time.

Charles
05-13-2009, 01:49 PM
Perhaps it's conflicting with some other styles on the page. Try hard-coding some constant for that value as a test case.

If you're going through all of this just to convert from Excel to HTML then I would suggest a better route. Use the Windows Scripting host and ActiveX to grab a recordset and then build an XHTML page with MSXML.

r0k3t
05-13-2009, 02:40 PM
Well to your first point - Yeah, I tried hard coding it and worked, if I set the width to 100 for each cell that is OK.

As for your second post - That may be an option, we have a site built in asp.net / c# and we want to take the XML and marry it to the style sheet on the fly, the trick is - only certain parts of the doc at certain times. I have no problem traversing the doc and selecting what I want, I just now need to display it.

Thanks!