Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How would I convert weight in decimal to pounds/ounces? 1

Status
Not open for further replies.

kellstee

Technical User
Dec 31, 2005
37
US
Total newbie here.

I'm working with a field in a shipping program that comes in pounds (i.e., 2.75 pounds) that I need to convert to two form fields:
pounds and ounces

For pounds, I would need the value to be 2
For ounces, I would need the value to be 12

I am XSL stupid.

Any help would be greatly appreciated!

Thanks!
Kelly
 
Suppose the element be like this.
[tt]
<pound>2.75</pound>
<pound>string</pound>
[/tt]
The template matching it may look something like this.
[tt]
<xsl:template match="pound">
<xsl:element name="weight">
<xsl:if test="boolean(number())">
<xsl:element name="pound">
<xsl:value-of select="floor(number())" />
</xsl:element>
<xsl:element name="ounce">
<xsl:value-of select="format-number((number() - floor(number())) * 16, '#.00')" />
</xsl:element>
</xsl:if>
<xsl:if test="not(boolean(number()))">
<xsl:value-of select="." />
</xsl:if>
</xsl:element>
</xsl:template>
[/tt]
It would produce something this apart from insignificant whitespaces.
[tt]
<weight>
<pound>2</pound>
<ounce>12.00</ounce>
</weight>
<weight>string</weight>
[/tt]
 
PERFECT! Thank you SO much for the help!

Kelly
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top