<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:i="iTree" version="1.0">
	<xsl:output method="html" encoding="UTF-8" indent="yes" doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
		doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"/>

	<xsl:variable name="pestlist" select="document('ipedpests.php')"/>
	
    <xsl:template name="IPED_HEADER">
        <th>PestCommonName</th>
        <th>PestScientificName</th>
        <th>TSDieback</th>
        <th>TSEpiSprout</th>
        <th>TSWiltFoli</th>
        <th>TSEnvStress</th>
        <th>TSHumStress</th>
        <th>TSNotes</th>
        <th>FTChewFoli</th>
        <th>FTDiscFoli</th>
        <th>FTAbnFoli</th>
        <th>FTInsectSigns</th>
        <th>FTFoliAffect</th>
        <th>FTNotes</th>
        <th>BBInsectSigns</th>
        <th>BBInsectPres</th>
        <th>BBDiseaseSigns</th>
        <th>BBProbLoc</th>
        <th>BBAbnGrowth</th>
        <th>BBNotes</th>
        <th>PestTS</th>
        <th>PestFT</th>
        <th>PestBB</th>
    </xsl:template>
    
    <xsl:template name="IPED_RECORD">
		<xsl:variable name="pestid" select="i:IPED/i:Pest"/>
        <td><xsl:choose>
            <xsl:when test="$pestid">
				<xsl:choose>
					<xsl:when test="$pestlist">
						<xsl:variable name="pest" select="$pestlist/i:Pests/i:Pest[i:Id=$pestid]"/>
						<xsl:choose>
							<xsl:when test="$pestid=-1">- Unknown -</xsl:when>
							<xsl:when test="$pest">
								<xsl:value-of select="$pest/i:CommonName"/>
							</xsl:when>
							<xsl:otherwise>
								<xsl:attribute name="class">err</xsl:attribute>
								Invalid/Obsolete value: <xsl:value-of select="$pestid"/>
							</xsl:otherwise>
						</xsl:choose>
					</xsl:when>
					<xsl:otherwise><xsl:value-of select="$pestid"/></xsl:otherwise>
				</xsl:choose>
            </xsl:when>
            <xsl:otherwise>- None -</xsl:otherwise>
        </xsl:choose></td>
        <td><xsl:choose>
            <xsl:when test="$pestid">
				<xsl:choose>
					<xsl:when test="$pestlist">
						<xsl:variable name="pest" select="$pestlist/i:Pests/i:Pest[i:Id=$pestid]"/>
						<xsl:choose>
							<xsl:when test="$pestid=-1">- Unknown -</xsl:when>
							<xsl:when test="$pest">
								<xsl:value-of select="$pest/i:ScientificName"/>
							</xsl:when>
							<xsl:otherwise>
								<xsl:attribute name="class">err</xsl:attribute>
								Invalid/Obsolete value: <xsl:value-of select="$pestid"/>
							</xsl:otherwise>
						</xsl:choose>
					</xsl:when>
					<xsl:otherwise><xsl:value-of select="$pestlist"/></xsl:otherwise>
				</xsl:choose>
            </xsl:when>
            <xsl:otherwise>- None -</xsl:otherwise>
        </xsl:choose></td>
        <td><xsl:choose>
            <xsl:when test="child::i:IPED/i:TreeStress/i:TSDieback">
                <xsl:choose>
                    <xsl:when test="i:IPED/i:TreeStress/i:TSDieback=2">
                        Twig dieback in upper/outer crown (&gt;10%), but not pervasive
                    </xsl:when>
                    <xsl:when test="i:IPED/i:TreeStress/i:TSDieback=3">
                        Pervasive twig dieback throughout the crown
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:attribute name="class">err</xsl:attribute>
                        Invalid/Obsolete value: <xsl:value-of select="i:IPED/i:TreeStress/i:TSDieback"/>
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:when>
            <xsl:otherwise>None noted</xsl:otherwise>
        </xsl:choose></td>
        <td><xsl:choose>
            <xsl:when test="i:IPED/i:TreeStress/i:TSEpiSprout">
                <xsl:choose>
                    <xsl:when test="i:IPED/i:TreeStress/i:TSEpiSprout=1">Yes</xsl:when>
                    <xsl:otherwise>
                        <xsl:attribute name="class">err</xsl:attribute>
                        Invalid/Obsolete value: <xsl:value-of select="i:IPED/i:TreeStress/i:TSEpiSprout"/>
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:when>
            <xsl:otherwise>No</xsl:otherwise>
        </xsl:choose></td>
        <td><xsl:choose>
            <xsl:when test="child::i:IPED/i:TreeStress/i:TSWiltFoli">
                <xsl:choose>
                    <xsl:when test="i:IPED/i:TreeStress/i:TSWiltFoli=1">Wilt, whole crown</xsl:when>
                    <xsl:when test="i:IPED/i:TreeStress/i:TSWiltFoli=2">Wilt, partial crown</xsl:when>
                    <xsl:otherwise>
                        <xsl:attribute name="class">err</xsl:attribute>
                        Invalid/Obsolete value: <xsl:value-of select="i:IPED/i:TreeStress/i:TSEpiSprout"/>
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:when>
            <xsl:otherwise>No wilt</xsl:otherwise>
        </xsl:choose></td>
        <td><xsl:choose>
            <xsl:when test="child::i:IPED/i:TreeStress/i:TSEnvStress">
                <xsl:choose>
                    <xsl:when test="i:IPED/i:TreeStress/i:TSEnvStress=1">Lightning strike</xsl:when>
                    <xsl:when test="i:IPED/i:TreeStress/i:TSEnvStress=2">Hail injury</xsl:when>
                    <xsl:when test="i:IPED/i:TreeStress/i:TSEnvStress=3">Sunscald</xsl:when>
                    <xsl:when test="i:IPED/i:TreeStress/i:TSEnvStress=4">Broken branches</xsl:when>
                    <xsl:when test="i:IPED/i:TreeStress/i:TSEnvStress=5">Flooding</xsl:when>
                    <xsl:when test="i:IPED/i:TreeStress/i:TSEnvStress=6">Drought/poor soil</xsl:when>
                    <xsl:when test="i:IPED/i:TreeStress/i:TSEnvStress=7">Other</xsl:when>
                    <xsl:when test="i:IPED/i:TreeStress/i:TSEnvStress=8">Frost cracks</xsl:when>
                    <xsl:otherwise>
                        <xsl:attribute name="class">err</xsl:attribute>
                        Invalid/Obsolete value: <xsl:value-of select="i:IPED/i:TreeStress/i:TSEnvStress"/>
                    </xsl:otherwise>
                </xsl:choose>                 
            </xsl:when>
            <xsl:otherwise>None noted</xsl:otherwise>
        </xsl:choose></td>
        <td><xsl:choose>
            <xsl:when test="child::i:IPED/i:TreeStress/i:TSHumStress">
                <xsl:choose>
                    <xsl:when test="i:IPED/i:TreeStress/i:TSHumStress=1">Topping/Poor pruning</xsl:when>
                    <xsl:when test="i:IPED/i:TreeStress/i:TSHumStress=2">Poor or restircted planting/mulching</xsl:when>
                    <xsl:when test="i:IPED/i:TreeStress/i:TSHumStress=3">Wounding of woody tissues</xsl:when>
                    <xsl:when test="i:IPED/i:TreeStress/i:TSHumStress=4">Salt/Chemicals</xsl:when>
                    <xsl:when test="i:IPED/i:TreeStress/i:TSHumStress=5">Other</xsl:when>
                    <xsl:otherwise>
                        <xsl:attribute name="class">err</xsl:attribute>
                        Invalid/Obsolete value: <xsl:value-of select="i:IPED/i:TreeStress/i:TSHumStress"/>
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:when>
            <xsl:otherwise>None noted</xsl:otherwise>
        </xsl:choose></td>
        <td><xsl:if test="child::i:IPED/i:TreeStress/i:TSNotes">
            <pre><xsl:value-of select="i:IPED/i:TreeStress/i:TSNotes"/></pre>
        </xsl:if></td>
        <td><xsl:choose>
            <xsl:when test="child::i:IPED/i:FoliageTwigs/i:FTChewFoli">
                <xsl:choose>
                    <xsl:when test="i:IPED/i:FoliageTwigs/i:FTChewFoli=1">Defoliation, &gt;10% of foliage, but not pervasive</xsl:when>
                    <xsl:when test="i:IPED/i:FoliageTwigs/i:FTChewFoli=2">Leaf mining, &gt;10% of foliage, but not pervasive</xsl:when>
                    <xsl:when test="i:IPED/i:FoliageTwigs/i:FTChewFoli=3">Chewing of the mid-rib only (any level)</xsl:when>
                    <xsl:when test="i:IPED/i:FoliageTwigs/i:FTChewFoli=4">Defoliation, pervasive throughout the crown</xsl:when>
                    <xsl:when test="i:IPED/i:FoliageTwigs/i:FTChewFoli=5">Leaf mining, pervasive throughout the crown</xsl:when>
                    <xsl:otherwise>
                        <xsl:attribute name="class">err</xsl:attribute>
                        Invalid/Obsolete value: <xsl:value-of select="i:IPED/i:FoliageTwigs/i:FTChewFoli"/>
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:when>
            <xsl:otherwise>None noted</xsl:otherwise>
        </xsl:choose></td>
        <td><xsl:choose>
            <xsl:when test="child::i:IPED/i:FoliageTwigs/i:FTDiscFoli">
                <xsl:choose>
                    <xsl:when test="i:IPED/i:FoliageTwigs/i:FTDiscFoli=1">Molting, spots, or blotches (any color)</xsl:when>
                    <xsl:when test="i:IPED/i:FoliageTwigs/i:FTDiscFoli=2">Marginal scorching (browning) of leaves</xsl:when>
                    <xsl:when test="i:IPED/i:FoliageTwigs/i:FTDiscFoli=3">Interveinal scorching (browning) of leaves</xsl:when>
                    <xsl:when test="i:IPED/i:FoliageTwigs/i:FTDiscFoli=4">White coating</xsl:when>
                    <xsl:when test="i:IPED/i:FoliageTwigs/i:FTDiscFoli=5">Complete browning/bronzing of leaves or needles</xsl:when>
                    <xsl:when test="i:IPED/i:FoliageTwigs/i:FTDiscFoli=6">Complete yellowing of leaves or needles</xsl:when>
                    <xsl:when test="i:IPED/i:FoliageTwigs/i:FTDiscFoli=7">Stippling</xsl:when>
                    <xsl:when test="i:IPED/i:FoliageTwigs/i:FTDiscFoli=8">Yellow/orange/white pustules</xsl:when>
                    <xsl:when test="i:IPED/i:FoliageTwigs/i:FTDiscFoli=9">Other</xsl:when>
                    <xsl:when test="i:IPED/i:FoliageTwigs/i:FTDiscFoli=10">Black coating (often sticky)</xsl:when>
                    <xsl:otherwise>
                        <xsl:attribute name="class">err</xsl:attribute>
                        Invalid/Obsolete value: <xsl:value-of select="i:IPED/i:FoliageTwigs/i:FTDiscFoli"/>
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:when>
            <xsl:otherwise>None noted</xsl:otherwise>
        </xsl:choose></td>
        <td><xsl:choose>
            <xsl:when test="child::i:IPED/i:FoliageTwigs/i:FTAbnFoli">
                <xsl:choose>
                    <xsl:when test="i:IPED/i:FoliageTwigs/i:FTAbnFoli=2">Foliage/twigs distorted (including galls on foliage)</xsl:when>
                    <xsl:when test="i:IPED/i:FoliageTwigs/i:FTAbnFoli=5">Other</xsl:when>
                    <xsl:when test="i:IPED/i:FoliageTwigs/i:FTAbnFoli=6">Witches' brooms present</xsl:when>
                    <xsl:otherwise>
                        <xsl:attribute name="class">err</xsl:attribute>
                        Invalid/Obsolete value: <xsl:value-of select="i:IPED/i:FoliageTwigs/i:FTAbnFoli"/>
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:when>
            <xsl:otherwise>None noted</xsl:otherwise>
        </xsl:choose></td>
        <td><xsl:choose>
            <xsl:when test="child::i:IPED/i:FoliageTwigs/i:FTInsectSigns">
                <xsl:choose>
                    <xsl:when test="i:IPED/i:FoliageTwigs/i:FTInsectSigns=1">Catepillars/sawflies feeding pervasive</xsl:when>
                    <xsl:when test="i:IPED/i:FoliageTwigs/i:FTInsectSigns=3">Beetles feeding pervasive</xsl:when>
                    <xsl:when test="i:IPED/i:FoliageTwigs/i:FTInsectSigns=4">Aphids/white cotton pervasive</xsl:when>
                    <xsl:when test="i:IPED/i:FoliageTwigs/i:FTInsectSigns=5">Bags pervasive</xsl:when>
                    <xsl:when test="i:IPED/i:FoliageTwigs/i:FTInsectSigns=6">Scales pervasive</xsl:when>
                    <xsl:when test="i:IPED/i:FoliageTwigs/i:FTInsectSigns=7">Tents/webbing on more than one branch</xsl:when>
                    <xsl:when test="i:IPED/i:FoliageTwigs/i:FTInsectSigns=8">Other</xsl:when>
                    <xsl:otherwise>
                        <xsl:attribute name="class">err</xsl:attribute>
                        Invalid/Obsolete value: <xsl:value-of select="i:IPED/i:FoliageTwigs/i:FTInsectSigns"/>
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:when>
            <xsl:otherwise>None noted</xsl:otherwise>
        </xsl:choose></td>
        <td><xsl:choose>
            <xsl:when test="child::i:IPED/i:FoliageTwigs/i:FTFoliAffect">
                <xsl:choose>
                    <xsl:when test="i:IPED/i:FoliageTwigs/i:FTFoliAffect=2">&gt;10%; &lt;30%</xsl:when>
                    <xsl:when test="i:IPED/i:FoliageTwigs/i:FTFoliAffect=3">&gt;30 but not the whole crown</xsl:when>
                    <xsl:when test="i:IPED/i:FoliageTwigs/i:FTFoliAffect=4">Whole crown affected</xsl:when>
                    <xsl:otherwise>
                        <xsl:attribute name="class">err</xsl:attribute>
                        Invalid/Obsolete value: <xsl:value-of select="i:IPED/i:FoliageTwigs/i:FTFoliAffect"/>
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:when>
            <xsl:otherwise>None noted</xsl:otherwise>
        </xsl:choose></td>
        <td><xsl:if test="child::i:IPED/i:FoliageTwigs/i:FTNotes">
            <pre><xsl:value-of select="i:IPED/i:FoliageTwigs/i:FTNotes"/></pre>
        </xsl:if></td>
        <td><xsl:choose>
            <xsl:when test="child::i:IPED/i:BranchesBole/i:BBInsectSigns">
                <xsl:choose>
                    <xsl:when test="i:IPED/i:BranchesBole/i:BBInsectSigns=1">Frass only</xsl:when>
                    <xsl:when test="i:IPED/i:BranchesBole/i:BBInsectSigns=2">Sawdust</xsl:when>
                    <xsl:when test="i:IPED/i:BranchesBole/i:BBInsectSigns=3">Pitch/resin exudation</xsl:when>
                    <xsl:when test="i:IPED/i:BranchesBole/i:BBInsectSigns=4">D-shaped exit holes</xsl:when>
                    <xsl:when test="i:IPED/i:BranchesBole/i:BBInsectSigns=5">Pencil round or oval exit holes (>=2mm)</xsl:when>
                    <xsl:when test="i:IPED/i:BranchesBole/i:BBInsectSigns=6">Shot holes</xsl:when>
                    <xsl:when test="i:IPED/i:BranchesBole/i:BBInsectSigns=7">Other holes</xsl:when>
                    <xsl:otherwise>
                        <xsl:attribute name="class">err</xsl:attribute>
                        Invalid/Obsolete value: <xsl:value-of select="i:IPED/i:BranchesBole/i:BBInsectSigns"/>
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:when>
            <xsl:otherwise>None noted</xsl:otherwise>
        </xsl:choose></td>
        <td><xsl:choose>
            <xsl:when test="child::i:IPED/i:BranchesBole/i:BBInsectPres">
                <xsl:choose>
                    <xsl:when test="i:IPED/i:BranchesBole/i:BBInsectPres=1">Catepillars</xsl:when>
                    <xsl:when test="i:IPED/i:BranchesBole/i:BBInsectPres=2">Beetles</xsl:when>
                    <xsl:when test="i:IPED/i:BranchesBole/i:BBInsectPres=3">Aphids</xsl:when>
                    <xsl:when test="i:IPED/i:BranchesBole/i:BBInsectPres=4">Scale</xsl:when>
                    <xsl:when test="i:IPED/i:BranchesBole/i:BBInsectPres=5">Carpenter Ants</xsl:when>
                    <xsl:when test="i:IPED/i:BranchesBole/i:BBInsectPres=6">Other</xsl:when>
                    <xsl:otherwise>
                        <xsl:attribute name="class">err</xsl:attribute>
                        Invalid/Obsolete value: <xsl:value-of select="i:IPED/i:BranchesBole/i:BBInsectPres"/>
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:when>
            <xsl:otherwise>None noted</xsl:otherwise>
        </xsl:choose></td>
        <td><xsl:choose>
            <xsl:when test="child::i:IPED/i:BranchesBole/i:BBDiseaseSigns">
                <xsl:choose>
                    <xsl:when test="i:IPED/i:BranchesBole/i:BBDiseaseSigns=1">Conks</xsl:when>
                    <xsl:when test="i:IPED/i:BranchesBole/i:BBDiseaseSigns=2">Fleshy mushrooms</xsl:when>
                    <xsl:when test="i:IPED/i:BranchesBole/i:BBDiseaseSigns=3">Cankers</xsl:when>
                    <xsl:when test="i:IPED/i:BranchesBole/i:BBDiseaseSigns=4">Bleeding/slime flux</xsl:when>
                    <xsl:when test="i:IPED/i:BranchesBole/i:BBDiseaseSigns=7">Resinosis/gummosis</xsl:when>
                    <xsl:when test="i:IPED/i:BranchesBole/i:BBDiseaseSigns=8">Other</xsl:when>
                    <xsl:when test="i:IPED/i:BranchesBole/i:BBDiseaseSigns=9">Decay</xsl:when>
                    <xsl:otherwise>
                        <xsl:attribute name="class">err</xsl:attribute>
                        Invalid/Obsolete value: <xsl:value-of select="i:IPED/i:BranchesBole/i:BBDiseaseSigns"/>
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:when>
            <xsl:otherwise>None noted</xsl:otherwise>
        </xsl:choose></td>
        <td><xsl:choose>
            <xsl:when test="child::i:IPED/i:BranchesBole/i:BBProbLoc">
                <xsl:choose>
                    <xsl:when test="i:IPED/i:BranchesBole/i:BBProbLoc=1">Branches</xsl:when>
                    <xsl:when test="i:IPED/i:BranchesBole/i:BBProbLoc=2">Bole and/or root collar</xsl:when>
                    <xsl:when test="i:IPED/i:BranchesBole/i:BBProbLoc=3">Both</xsl:when>
                    <xsl:otherwise>
                        <xsl:attribute name="class">err</xsl:attribute>
                        Invalid/Obsolete value: <xsl:value-of select="i:IPED/i:BranchesBole/i:BBProbLoc"/>
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:when>
            <xsl:otherwise>None noted</xsl:otherwise>
        </xsl:choose></td>
        <td><xsl:choose>
            <xsl:when test="child::i:IPED/i:BranchesBole/i:BBAbnGrowth">
                <xsl:choose>
                    <xsl:when test="i:IPED/i:BranchesBole/i:BBAbnGrowth=5">Loose bark only</xsl:when>
                    <xsl:when test="i:IPED/i:BranchesBole/i:BBAbnGrowth=6">Other</xsl:when>
                    <xsl:when test="i:IPED/i:BranchesBole/i:BBAbnGrowth=7">Rizomorphs present</xsl:when>
                    <xsl:when test="i:IPED/i:BranchesBole/i:BBAbnGrowth=8">Mycelial fans or pads present</xsl:when>
                    <xsl:when test="i:IPED/i:BranchesBole/i:BBAbnGrowth=9">Insect boring or galleries causing loose bark</xsl:when>
                    <xsl:otherwise>
                        <xsl:attribute name="class">err</xsl:attribute>
                        Invalid/Obsolete value: <xsl:value-of select="i:IPED/i:BranchesBole/i:BBAbnGrowth"/>
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:when>
            <xsl:otherwise>None noted</xsl:otherwise>
        </xsl:choose></td>
        <td><xsl:if test="child::i:IPED/i:BranchesBole/i:BBNotes">
            <pre><xsl:value-of select="child::i:IPED/i:BranchesBole/i:BBNotes"/></pre>
        </xsl:if></td>
        <td><xsl:choose>
            <xsl:when test="child::i:IPED/i:TreeStress">Yes</xsl:when>
            <xsl:otherwise>No</xsl:otherwise>
        </xsl:choose></td>
        <td><xsl:choose>
            <xsl:when test="child::i:IPED/i:FoliageTwigs">Yes</xsl:when>
            <xsl:otherwise>No</xsl:otherwise>
        </xsl:choose></td>
        <td><xsl:choose>
            <xsl:when test="child::i:IPED/i:BranchesBole">Yes</xsl:when>
            <xsl:otherwise>No</xsl:otherwise>
        </xsl:choose></td>
    </xsl:template>
</xsl:stylesheet>

