Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to Use Percent Sign (%) in XSL Variable

754 views
Skip to first unread message

KW

unread,
Dec 27, 2006, 12:37:35 PM12/27/06
to
I am having a problem using the percent sign in a variable and cannot
figure out how to get it to work. I am getting the following parse
error...

Expected end of the expression, found '%'...

when attempting this...

<xsl:variable name="column-width" select="25%"></xsl:variable>

I know it has something to do with the use of the percent sign, but I
cannot figure out how to get it to work. I want to use the variable
within other areas of the style sheet to set the width of columns.

For example...

...
<table>
<tr>
<td width="{$column-width}">SOME CONTENT</td>
</tr>
</table>
...

I appreciate any help you can provide!

Kevin

Martin Honnen

unread,
Dec 27, 2006, 12:44:34 PM12/27/06
to
KW wrote:

> <xsl:variable name="column-width" select="25%"></xsl:variable>

If you want the variable value to be of type string then you need


<xsl:variable name="column-width" select="'25%'"></xsl:variable>


--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/

KW

unread,
Dec 27, 2006, 12:47:36 PM12/27/06
to
OK... I figured out how to do what I wanted by including the value of
the variable in the text node area for the variable element...

<xsl:variable name="column-width">25%</xsl:variable>

This approach works fine.

So, I am assuming that the % sign causes a problem with XPath
expressions, and I still would be interested in how to utilize the %
literal character in an expression like this.

Kevin

KW

unread,
Dec 27, 2006, 1:03:08 PM12/27/06
to
Thanks. I am new to XPath expressions. That is a newbie oversight for
sure!

AndrewF

unread,
Dec 28, 2006, 4:47:15 AM12/28/06
to
Hi KW,

Just so you know why this didn't work, rather than just that it doesn't
work, this is why.

In your first version:

<xsl:variable name="column-width" select="25%"></xsl:variable>

You are telling the XSL parser to make a variable called column-width
and then select using XPath the entity called 25%

25% as an XPath name doesn't work because the % character has no
relevance in XPath and nor can it be used as an element or attribute
name either.

What you did ultimately by changing your construct to:

<xsl:variable name="column-width">25%</xsl:variable>

And what Martin suggested by doing this:

<xsl:variable name="column-width" select="'25%'"></xsl:variable>

Was the define the variable as using a string - in your version you've
implicitly done this by setting the variable in the text area of the
element, Martin's one is doing it explicitly by putting '25%' in the
select statement which says select the text '25%' rather than the XPath
that equals 25%.

Cheers
AndrewF

---
XML Infinity - www.xmlinfinity.com - Content management where the
possibilities are endless

KW

unread,
Dec 29, 2006, 9:05:15 AM12/29/06
to
Thanks for the info. I will be spending some more time learning the
details of XPath expressions. --KW
0 new messages