How do I display HeightFeet element?

Here should go questions about transforming XML with XSLT and FOP.
winkimjr2
Posts: 62
Joined: Thu Jun 26, 2014 9:00 pm

How do I display HeightFeet element?

Post by winkimjr2 » Thu Dec 18, 2014 6:32 pm

Based on my xml code, I want to convert the HeightFeet number into inches.
I also want to check that the HeightFeet is not less than 48 inches and not greater than 95 inches.
How do I do this?
Can someone help me?
My xml code

Code: Select all


<Party ID="1116666" InternalPartyID="1610656384">
<Gender Word="F">Female</Gender>
<HeightFeet>5</HeightFeet>
<WeightPounds>130</WeightPounds>
<EyeColor Word="BLU">Blue</EyeColor>
</Party>
Desired output

Code: Select all


<nc:PersonHeightMeasure>
<nc:MeasureText>60</nc:MeasureText>
<nc:MeasureUnitText>inches</nc:MeasureUnitText>
<nc:LengthUnitCode>INH</nc:LengthUnitCode>
</nc:PersonHeightMeasure>
Output I am getting

Code: Select all


<nc:PersonHeightMeasure>
<nc:MeasureText>NaN</nc:MeasureText>
<nc:MeasureUnitText>inches</nc:MeasureUnitText>
<nc:LengthUnitCode>INH</nc:LengthUnitCode>
</nc:PersonHeightMeasure>
xslt code

Code: Select all


<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>

winkimjr2
Posts: 62
Joined: Thu Jun 26, 2014 9:00 pm

Re: How do I display HeightFeet element?

Post by winkimjr2 » Fri Dec 19, 2014 5:19 pm

winkimjr2 wrote:Based on my xml code, I want to convert the HeightFeet number into inches.
I also want to check that the HeightFeet is not less than 48 inches and not greater than 95 inches.
How do I do this?
Can someone help me?
My xml code

Code: Select all


<Party ID="1116666" InternalPartyID="1610656384">
<Gender Word="F">Female</Gender>
<HeightFeet>5</HeightFeet>
<HeightInches>5</HeightInches>
<WeightPounds>130</WeightPounds>
<EyeColor Word="BLU">Blue</EyeColor>
</Party>
Desired output

Code: Select all


<nc:PersonHeightMeasure>
<nc:MeasureText>60</nc:MeasureText>
<nc:MeasureUnitText>inches</nc:MeasureUnitText>
<nc:LengthUnitCode>INH</nc:LengthUnitCode>
</nc:PersonHeightMeasure>
Output I am getting

Code: Select all


<nc:PersonHeightMeasure>
<nc:MeasureText>NaN</nc:MeasureText>
<nc:MeasureUnitText>inches</nc:MeasureUnitText>
<nc:LengthUnitCode>INH</nc:LengthUnitCode>
</nc:PersonHeightMeasure>
xslt code

Code: Select all


<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>

Radu
Posts: 6980
Joined: Fri Jul 09, 2004 5:18 pm

Re: How do I display HeightFeet element?

Post by Radu » Tue Dec 23, 2014 12:10 pm

Hi,

It might depend also on the XSLT processor you are using. I tried to create a small 2.0 XSLT stylesheet with your code and run it with Saxon 9, the XSLT stylesheet I tested was like this:

Code: Select all

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
version="2.0" xmlns:nc="gogo">
<xsl:output indent="yes"></xsl:output>
<xsl:template match="Party">
<nc:PersonHeightMeasure>
<nc:MeasureText>
<xsl:choose>
<xsl:when test="HeightFeet and HeightInches">
<xsl:variable name="feet" select="HeightFeet"/>
<xsl:variable name="inches" select="HeightInches"/>
<xsl:value-of select="$feet * 12 + $inches "/>
</xsl:when>
<xsl:when test="HeightFeet">
<xsl:variable name="feet" select="HeightFeet"/>
<xsl:value-of select="$feet * 12"/>
</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:template>
</xsl:stylesheet>
and it seemed to work for me. I added in the XSLT one more choice to take into account that the HeightInches element might sometimes be missing from the XML document.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com

Post Reply