Wednesday, 10 December 2014

I want to display the first petition only when there is more than one in xml document



I have a xml with 2 petitioners where petitioner = true. I only want to display the first one even when if there is more than one. How do I do this? I am using a template for the petitioner which I have added here below.


Desired output is only one petition like this



<ext:ProtectedParty>
<ext:PersonBirthDate ext:approximateDateIndicator="false" ext:currentIndicator="true">1969-08-06</ext:PersonBirthDate>
<nc:PersonName>
<nc:PersonFullName>MARKO, KEEM</nc:PersonFullName>
</nc:PersonName>
<ext:PersonRaceCode/>
<nc:PersonSexCode>F </nc:PersonSexCode>
<ext:PetitionerIndicator>true</ext:PetitionerIndicator>
</ext:ProtectedParty>


Current output which is wrong



<ext:ProtectedParty>
<ext:PersonBirthDate ext:approximateDateIndicator="false" ext:currentIndicator="true">1969-08-06</ext:PersonBirthDate>
<nc:PersonName>
<nc:PersonFullName>MARKO, KEEM</nc:PersonFullName>
</nc:PersonName>
<ext:PersonRaceCode/>
<nc:PersonSexCode>F </nc:PersonSexCode>
<ext:PetitionerIndicator>true</ext:PetitionerIndicator>
</ext:ProtectedParty>
<ext:ProtectedParty>
<ext:PersonBirthDate ext:approximateDateIndicator="false" ext:currentIndicator="true">1978-08-01</ext:PersonBirthDate>
<nc:PersonName>
<nc:PersonFullName>JOANN, NENNI</nc:PersonFullName>
</nc:PersonName>
<ext:PersonRaceCode/>
<nc:PersonSexCode>F </nc:PersonSexCode>
<ext:PetitionerIndicator>true</ext:PetitionerIndicator>
</ext:ProtectedParty>


My xml document



<ProtectionOrderParties>
<ProtectionOrderParty InternalPartyID="77">
<ProtectionOrderPartyNames>
<ProtectionOrderPartyName Current="true" InternalNameID="77" FormattedName="Marko, Keem"/>
</ProtectionOrderPartyNames>
<ProtectionOrderConnection>
<Petitioner>true</Petitioner>
<ProtectedParty>true</ProtectedParty>
</ProtectionOrderConnection>
</ProtectionOrderParty>
<ProtectionOrderParty InternalPartyID="97">
<ProtectionOrderPartyNames>
<ProtectionOrderPartyName Current="true" InternalNameID="53" FormattedName="JoAnn, Nenni"/>
</ProtectionOrderPartyNames>
<ProtectionOrderConnection>
<Petitioner>true</Petitioner>
<ProtectedParty>true</ProtectedParty>
</ProtectionOrderConnection>
</ProtectionOrderParty>


My xslt code



<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="3.0" xmlns:xsl="http://ift.tt/tCZ8VR">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template name="ProtectionOrder">
<ext:ProtectionOrder>
<!--Petitioner-->
<xsl:for-each select="ProtectionOrderParties/ProtectionOrderParty[(ProtectionOrderConnection/Petitioner='true') and (ProtectionOrderConnection/ProtectedParty='false')][1]">
<xsl:for-each select="//Integration/Party[@InternalPartyID=current()/@InternalPartyID]">
<xsl:call-template name="Petitioner"/>
</xsl:for-each>
</xsl:for-each>
</ext:ProtectionOrder>

</xsl:template>

<!--Petitioner Template-->
<xsl:template name="Petitioner">
<ext:Petitioner>
<ext:AddressReference>
<xsl:for-each select="Address[@PartyCurrent='true']">
<xsl:attribute name="ext:currentIndicator"><xsl:value-of select="@PartyCurrent"/></xsl:attribute>
<nc:LocationReference>
<xsl:attribute name="s:ref"><xsl:text>INT</xsl:text><xsl:value-of select="@ID"/></xsl:attribute>
</nc:LocationReference>
</xsl:for-each>
</ext:AddressReference>
<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>
<nc:PersonName>
<nc:PersonGivenName>
<xsl:value-of select="PartyName/NameFirst"/>
</nc:PersonGivenName>
<nc:PersonMiddleName>
<xsl:value-of select="PartyName/NameMiddle"/>
</nc:PersonMiddleName>
<nc:PersonSurName>
<xsl:value-of select="PartyName/NameLast"/>
</nc:PersonSurName>
<nc:PersonNameSuffixText>
<xsl:value-of select="PartyName/NameSuffix"/>
</nc:PersonNameSuffixText>
<nc:PersonFullName>
<xsl:value-of select="PartyName/FormattedName"/>
</nc:PersonFullName>
</nc:PersonName>
<ext:PersonRaceCode>
<xsl:value-of select="//Case/CaseParty[@InternalPartyID=current()/@InternalPartyID]/ObservedRace/@Word"/>
</ext:PersonRaceCode>
<nc:PersonSexCode>
<xsl:value-of select="Party/Gender/@Word"/>
</nc:PersonSexCode>
</ext:Petitioner>
</xsl:template>
</xsl:stylesheet>

No comments:

Post a Comment