Saturday 15 June 2013

xml - How do I display all the date of birth from a node? -



xml - How do I display all the date of birth from a node? -

i have xml document 3 dates of birth, current, approximate , just date. want display 3 dates output.

my xml code

<party id="76" internalpartyid="18"> <gender word="f ">female</gender> <approximatedob>03/4/1956</approximatedob> <dateofbirth current="true">05/21/1956</dateofbirth> <dateofbirth>04/21/1956</dateofbirth> </party>

my xslt code

<!--respondent --> <xsl:for-each select="respondentpartyid"> <xsl:for-each select="//caseparty[(@internalpartyid=current()/@internalpartyid) , (connection[(@word='rsp') ])]"> <xsl:for-each select="//party[@internalpartyid=current()/@internalpartyid]"> <xsl:call-template name="respondent"> <xsl:with-param name="pprotectionorderid"> <xsl:value-of select="$vprotectionorderid"/> </xsl:with-param> </xsl:call-template> </xsl:for-each> </xsl:for-each> </xsl:for-each> <!--respondent template--> <xsl:template name="respondent"> <xsl:param name="pprotectionorderid"/> <ext:respondent> <!--guardian --> <xsl:for-each select="//caseparty[(connection[(@word='grd')])][1]"> <xsl:for-each select="//party[@internalpartyid=current()/@internalpartyid]"> <xsl:call-template name="guardian"/> </xsl:for-each> </xsl:for-each> <ext:personbirthdate> <xsl:choose> <xsl:when test="dateofbirth[@current='true']"> <xsl:attribute name="ext:approximatedateindicator">false</xsl:attribute> <xsl:attribute name="ext:currentindicator">true</xsl:attribute> <xsl:value-of select="mscef:formatdate(string(dateofbirth[@current='true']))"/> </xsl:when> <xsl:when test="approximatedob"> <xsl:attribute name="ext:approximatedateindicator">true</xsl:attribute> <xsl:attribute name="ext:currentindicator">true</xsl:attribute> <xsl:value-of select="mscef:formatdate(string(approximatedob))"/> </xsl:when> </xsl:choose> </ext:personbirthdate> </ext:respondent>

how alter xslt code output looks 1 below. right xslt returns current date of birth:

<ext:personbirthdate ext:approximatedateindicator="false" ext:currentindicator="true">1956-05-21</ext:personbirthdate> <ext:personbirthdate ext:approximatedateindicator="true" ext:currentindicator="false">1956-03-04</ext:personbirthdate> <ext:personbirthdate ext:approximatedateindicator="false" ext:currentindicator="false">1956-04-21</ext:personbirthdate>

consider having template match each possible 'date of birth' element. this:

<xsl:template match="dateofbirth"> <ext:personbirthdate> <xsl:attribute name="approximatedateindicator">false</xsl:attribute> <xsl:attribute name="currentindicator">false</xsl:attribute> <xsl:value-of select="."/> </ext:personbirthdate> </xsl:template> <xsl:template match="dateofbirth[@current='true']"> <ext:personbirthdate> <xsl:attribute name="approximatedateindicator">false</xsl:attribute> <xsl:attribute name="currentindicator">true</xsl:attribute> <xsl:value-of select="."/> </ext:personbirthdate> </xsl:template> <xsl:template match="approximatedob"> <ext:personbirthdate> <xsl:attribute name="approximatedateindicator">true</xsl:attribute> <xsl:attribute name="currentindicator">false</xsl:attribute> <xsl:value-of select="."/> </ext:personbirthdate> </xsl:template>

then can alter existing xslt code this, should output 3 dates.

<xsl:apply-templates select="approximatedob|dateofbirth" />

it quite repetitive have many templates, should no problem combine templates one.

try xslt starters:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform" xmlns:ext="ext"> <xsl:output method="xml" indent="yes" /> <xsl:template match="party"> <ext:respondent> <xsl:apply-templates select="approximatedob|dateofbirth" /> </ext:respondent> </xsl:template> <xsl:template match="approximatedob|dateofbirth"> <ext:personbirthdate approximatedateindicator="{local-name() = 'approximatedob'}" currentindicator="{@current = 'true'}"> <xsl:value-of select="."/> </ext:personbirthdate> </xsl:template> </xsl:stylesheet>

note utilize of attribute value templates farther simplify code.

when above xslt applied next xml

<party id="76" internalpartyid="18"> <gender word="f ">female</gender> <approximatedob>03/4/1956</approximatedob> <dateofbirth current="true">05/21/1956</dateofbirth> <dateofbirth>04/21/1956</dateofbirth> </party>

the next output

<ext:respondent xmlns:ext="ext"> <ext:personbirthdate approximatedateindicator="true" currentindicator="false">03/4/1956</ext:personbirthdate> <ext:personbirthdate approximatedateindicator="false" currentindicator="true">05/21/1956</ext:personbirthdate> <ext:personbirthdate approximatedateindicator="false" currentindicator="false">04/21/1956</ext:personbirthdate> </ext:respondent>

(i have left out date formatting, because don't have extension function test locally)

edit: fit xslt code, this

<!--respondent --> <xsl:for-each select="respondentpartyid"> <xsl:for-each select="//caseparty[(@internalpartyid=current()/@internalpartyid) , (connection[(@word='rsp') ])]"> <xsl:for-each select="//party[@internalpartyid=current()/@internalpartyid]"> <xsl:call-template name="respondent"> <xsl:with-param name="pprotectionorderid"> <xsl:value-of select="$vprotectionorderid"/> </xsl:with-param> </xsl:call-template> </xsl:for-each> </xsl:for-each> </xsl:for-each> <!--respondent template--> <xsl:template name="respondent"> <xsl:param name="pprotectionorderid"/> <ext:respondent> <!--guardian --> <xsl:for-each select="//caseparty[(connection[(@word='grd')])][1]"> <xsl:for-each select="//party[@internalpartyid=current()/@internalpartyid]"> <xsl:call-template name="guardian"/> </xsl:for-each> </xsl:for-each> <xsl:apply-templates select="approximatedob|dateofbirth" /> </ext:respondent> </xsl:template> <xsl:template match="approximatedob|dateofbirth"> <ext:personbirthdate approximatedateindicator="{local-name() = 'approximatedob'}" currentindicator="{@current = 'true'}"> <xsl:value-of select="mscef:formatdate(string(.))"/> </ext:personbirthdate> </xsl:template>

xml xslt

No comments:

Post a Comment