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 August 20th, 2014, 10:37 AM
Friend of Wrox
 
Join Date: Apr 2013
Posts: 101
Thanks: 14
Thanked 0 Times in 0 Posts
Default How do I check height and weight

I am wondering how to change my xslt code so that it checks if height and weight. I want to check if the weight is less than 50 pounds or greater than 499 pounds then this will not be displayed in the output.
And for the height I want to check if height is less than 48 inches or greater than 95 inches then this will not be displayed in the output.
Weight xslt code
Code:
<xsl:if test="WeightPounds">
		<nc:PersonWeightMeasure>
		    <nc:MeasureText>
		       <xsl:choose>
			<xsl:when test="WeightPounds">
			   <xsl:value-of select="WeightPounds"/>
			</xsl:when>
			</xsl:choose>
		</nc:MeasureText>
XSLT code for Height
Code:
<xsl:if test="HeightFeet">
		<nc:PersonHeightMeasure>
		   <nc:MeasureText>
			<xsl:choose>
		           <xsl:when test="HeightFeet">
				<xsl:value-of select="(HeightFeet*12)+HeightInches"/>
				</xsl:when>
			</xsl:choose>
			   </nc:MeasureText>
				<nc:MeasureUnitText>
			           <xsl:text>inches</xsl:text>
			  </nc:MeasureUnitText>
					<nc:LengthUnitCode>
						<xsl:text>INH</xsl:text>
					</nc:LengthUnitCode>
				</nc:PersonHeightMeasure>
			</xsl:if>
 
Old August 20th, 2014, 12:04 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Did you know that your code

Code:
                        <xsl:choose>
			<xsl:when test="WeightPounds">
			   <xsl:value-of select="WeightPounds"/>
			</xsl:when>
			</xsl:choose>
could simply be written

Code:
<xsl:value-of select="WeightPounds"/>
since if WeightPounds is absent, nothing will be displayed by xsl:value-of? XSLT doesn't need to be as verbose as some people think.

If you only want it displayed if a condition is satisfied, just add the condition:

Code:
<xsl:value-of select="WeightPounds[. &gt;= 50 and . &lt;= 499]"/>
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
The Following User Says Thank You to mhkay For This Useful Post:
winkimjr2 (August 22nd, 2014)
 
Old August 22nd, 2014, 11:08 AM
Friend of Wrox
 
Join Date: Apr 2013
Posts: 101
Thanks: 14
Thanked 0 Times in 0 Posts
Default

That was awesome. I am new to this xml/xslt and I am finding different/better ways of writing code everyday. Your reply was in particular very helpful.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Determine image weight YoungLuke C# 4 November 26th, 2007 05:34 PM
Fixed table height and row height rajanikrishna HTML Code Clinic 3 January 18th, 2007 12:42 AM
Change height of div element if < window height JoelJunstrom Javascript How-To 1 October 10th, 2003 09:14 AM





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