mrwienerdog
mrwienerdog

Reputation: 825

How do I use xsl format-number func. on an attribute?

I have a value I am parsing from an xml file that I need to stick into my table. I have the number displaying, but need to have it as "#,###.0" instead of just the integer. I got the number using:

<td><xsl:value-of select="amount/@pricePerUnit"/></td>

The price per unit is, let's say, 2. As I said, I need "2.0".

I have tried

<td><xsl:value-of select="amount/@format-number(pricePerUnit,'#,###.0')"/></td>

and

<td><xsl:value-of select="amount/format-number(@pricePerUnit,'#,###.0')"/></td>

but neither works. Have looked around with the googles, but can't seem to find the correct syntax. Can anyone help?

Upvotes: 0

Views: 574

Answers (1)

Xavier Holt
Xavier Holt

Reputation: 14619

Try putting your xpath inside the function, as the first argument:

format-number(amount/@pricePerUnit, '#,###.0')

That'll find the value of your attribute node, pass it into the format-number() function, and give you back the return value.

Upvotes: 1

Related Questions