xslt 1.0 How to format output based on a conditional test -
i'm trying read xml file has series of sub-nodes. based on value of 1 of subnodes (within set), want particular output bolded.
here xml example:
<documentationof> <event> <effectivetime> <low value="9/4/2013" /> </effectivetime> </event> </documentationof> <entry> <substanceadministration> <text> <reference value=""> </reference> </text> <effectivetime> <low value="5/13/2013 12:00:00 am" /> <high value="unk" /> </effectivetime> <consumable> <manufacturedproduct> <manufactueredmaterial> <code code="" displayname="product 1"> </code> </manufacturedmaterial> </manufacturedproduct> </consumable> </substanceadministration> </entry> <entry> <substanceadministration> <text> <reference value=""> </reference> </text> <effectivetime> <low value="9/4/2013 12:00:00 am" /> <high value="unk" /> </effectivetime> <consumable> <manufacturedproduct> <manufactueredmaterial> <code code="" displayname="product 2"> </code> </manufacturedmaterial> </manufacturedproduct> </consumable> </substanceadministration> </entry> <entry> <substanceadministration> <text> <reference value=""> </reference> </text> <effectivetime> <low value="5/13/2013 12:00:00 am" /> <high value="unk" /> </effectivetime> <consumable> <manufacturedproduct> <manufactueredmaterial> <code code="" displayname="product 3"> </code> </manufacturedmaterial> </manufacturedproduct> </consumable> </substanceadministration> </entry>
i want code/@displayname appear (which can for-each , work) if effectivetime/low/@value today's date (which in documentationof/event/effectivetime/low/@value), want in bold:
product 1 <b>product 2</b> product 3
here xsl snipped this:
<xsl:for-each select="entry"> <xsl:value-of select="substanceadministration/consumable/manufacturedproduct/manufacturedmaterial/code/@displayname" /> <br /> </xsl:for-each>
i realize should doing own template, didn't write xsl msyelf , in interests of time, making what's there. however, trying redo in parallel templates (the right way) still need know best way check effectivetime/low/@value make entry bold in output.
thanks in advance help.
here process use.
first create global variable date today.
<xsl:variable name="today" select="//documentationof/event/effectivetime/low/@value"/>
then can update for-each
include call template , span
add bold styling to.
<xsl:for-each select="entry"> <xsl:variable name="istoday"> <xsl:call-template name="comparetoday"> <xsl:with-param name="date" select="substanceadministration/effectivetime/low/@value"/> </xsl:call-template> </xsl:variable> <span> <xsl:if test="$istoday = 'true'"> <xsl:attribute name="style"> <xsl:text>font-weight:bold;</xsl:text> </xsl:attribute> </xsl:if> <xsl:value-of select="substanceadministration/consumable/manufacturedproduct/manufacturedmaterial/code/@displayname" /> </span> <br /> </xsl:for-each>
and comparetoday
named template compare 2 dates.
<xsl:template name="comparetoday"> <xsl:param name="date"/> <xsl:if test="substring($date,0,(string-length($date) - 11)) = $today"> <xsl:text>true</xsl:text> </xsl:if> </xsl:template>
you notice in above template had take substring of date matches format of today date variable. if format varies 2 need update template convert them both same format before compare them.
after running produces output.
<span>product 1</span><br/> <span style="font-weight:bold;">product 2</span><br/> <span>product 3</span><br/>
Comments
Post a Comment