xml - Changing result display based on Element value -
i have xml contains info college classes. classes displayed title, course of study number , total number of credits.
my xslt groups info area of study , lists classes course of study number , provides course of study description , total number of credits. working fine, i'd tweak final display of credit hours.
each class has minimum # of credits 1-4. classes have maximum # of credits.
my xslt pulls both minimum credits <crsmincred1>
, maximum credits <crsmaxcred1>
if exist.
then, xslt builds final display appears 1 of following:
when class info features <crsmincred1>
display looks this: "1 credit hours" "2 credit hours" "3 credit hours" "4 credit hours"
when class info features both <crsmincred1>
, <crsmaxcred1>
display looks this: "1 4 credit hours."
everything's fine except first item. when course of study has "1" minimum credit , no maximum credits, i'd the display be:
"1 credit hour"
i've tried create "variable" , "if" statements without success.
here's sample xml:
<?xml version="1.0" encoding="utf-8"?> <crystalreport> <details level="1"> <section sectionnumber="0"> <crstitle1>clinical applications of ct i</crstitle1> <deptsdesc1>diagnostic medical imaging</deptsdesc1> <crsno1>2511</crsno1> <crsmincred1>3</crsmincred1> <crsmaxcred1/> </section> </details> <details level="1"> <section sectionnumber="0"> <crstitle1>clinical applications of ct ii</crstitle1> <crsdepts1>dmi</crsdepts1> <deptsdesc1>diagnostic medical imaging 2</deptsdesc1> <crsno1>2512</crsno1> <crsmincred1>1</crsmincred1> <crsmaxcred1>4</crsmaxcred1> </section> </details> <details level="1"> <section sectionnumber="0"> <crstitle1>clinical applications of ct iii</crstitle1> <crsdepts1>dmi</crsdepts1> <deptsdesc1>diagnostic medical imaging 3</deptsdesc1> <crsno1>2513</crsno1> <crsmincred1>1</crsmincred1> <crsmaxcred1/> </section> </details> </crystalreport>
here's portion of xslt i'm trying work:
<xsl:template match="crystalreport"> ... <xsl:apply-templates select="section/crsmincred1|section/crsmaxcred1"/> </xsl:template> <xsl:template match="section/crsmincred1"> <xsl:if test=". = 1"> <mincredit><xsl:value-of select="."/></mincredit><xsl:text> credit hour</xsl:text></xsl:if> <xsl:if test=". > 1"> <mincredit><xsl:value-of select="."/></mincredit><xsl:text> credit hours</xsl:text></xsl:if> </xsl:template> <xsl:template match="section/crsmaxcred1[string-length() != 0]"> <xsl:text> </xsl:text><maxcredits><xsl:value-of select="normalize-space(.)" /></maxcredits><xsl:text> credit hours</xsl:text> </xsl:template> </xsl:stylesheet>
this stylesheet produces want until class shows both minimum , and maximum credits , next display: "1 credit hr 4 credit hours"
any help appreciated.
i'd suggest doing this:
<xsl:template match="crystalreport"> ... <xsl:apply-templates select="section" mode="credits"/> </xsl:template> <xsl:template match="section" mode="credits"> <xsl:apply-templates select="crsmincred1" /> <xsl:text> credit hour</xsl:text> <xsl:apply-templates select="crsmincred1[. != 1]" mode="pluralize" /> </xsl:template> <xsl:template match="section[normalize-space(crsmaxcred1)]" mode="credits"> <xsl:apply-templates select="crsmincred1" /> <xsl:text> </xsl:text> <xsl:apply-templates select="crsmaxcred1" /> <xsl:text> credit hour</xsl:text> <xsl:apply-templates select="crsmaxcred1[. != 1]" mode="pluralize"/> </xsl:template> <xsl:template match="crsmincred1"> <mincredit> <xsl:value-of select="." /> </mincredit> </xsl:template> <xsl:template match="crsmaxcred1"> <maxcredit> <xsl:value-of select="." /> </maxcredit> </xsl:template> <xsl:template match="*" mode="pluralize"> <xsl:text>s</xsl:text> </xsl:template>
xml xslt
No comments:
Post a Comment