How do I remove a semi colon when I have only one party in x

Here should go questions about transforming XML with XSLT and FOP.
winkimjr2
Posts: 53

How do I remove a semi colon when I have only one party in x

Tue Dec 30, 2014 1:28 am

I would like to display a name followed by address and a semi colon and another name followed by address when xml document has 2 parties in the conditions element. My output is displaying the names with a semi colon and then the address. I would like to display a name followed by its associated address and then a semi colon and then the second name and its address.
Also when my xml document has only one name in the conditions element, a semi colon is added at the end which I do not want.
How do I change me xslt to only add a semi colon after the first name and its address and not add a semi colon when there is only one name in the conditions element?
My xml document

Code: Select all

<ProtectionOrder Op="E" InternalProtectionOrderID="2571" xmlns:user="http://tylertechnologies.com">
   <ProtectionOrderParties>
      <ProtectionOrderParty InternalPartyID="1614451562">
         <ProtectionOrderPartyNames>
            <ProtectionOrderPartyName Current="true" InternalNameID="1615263003" FormattedName="Petitioner, Richard S"/>
         </ProtectionOrderPartyNames>
         <ProtectionOrderConnection>
            <Petitioner>true</Petitioner>
            <ProtectedParty>true</ProtectedParty>
         </ProtectionOrderConnection>
         <MNProtectionOrderPartyAdditional xmlns:fn="http://www.w3.org/2005/xpath-functions">
            <ProtectedAddresses>
               <Address InternalAddressID="1618211271" Type="Standard">
                  <Location Word="HOME">Home</Location>
                  <Confidential>false</Confidential>
                  <AddressLine2>3 Back Petitioner ST</AddressLine2>
                  <AddressLine4>My Town, MN, 55555</AddressLine4>
                  <Block>3</Block>
                  <Street>Back Petitioner</Street>
                  <AddrSfxKy Word="ST">Street</AddrSfxKy>
                  <City>My Town</City>
                  <State>MN</State>
                  <Zip>55555</Zip>
                  <Foreign>false</Foreign>
               </Address>
            </ProtectedAddresses>
         </MNProtectionOrderPartyAdditional>
      </ProtectionOrderParty>
      <ProtectionOrderParty InternalPartyID="1614451515">
         <ProtectionOrderPartyNames>
            <ProtectionOrderPartyName Current="true" InternalNameID="1615262953" FormattedName="Dickens, Little"/>
         </ProtectionOrderPartyNames>
         <ProtectionOrderConnection>
            <Petitioner>false</Petitioner>
            <FilingParty>false</FilingParty>
            <ProtectedParty>true</ProtectedParty>
            <Minor>true</Minor>
         </ProtectionOrderConnection>
         <MNProtectionOrderPartyAdditional xmlns:fn="http://www.w3.org/2005/xpath-functions">
            <ProtectedAddresses>
               <Address InternalAddressID="1618211278" Type="Foreign">
                  <Location Word="DAYCARE">Daycare</Location>
                  <Confidential>false</Confidential>
                  <AddressLine1>Foreign Address</AddressLine1>
                  <AddressLine2>FA line 2</AddressLine2>
                  <AddressLine3>FA line 3</AddressLine3>
                  <AddressLine4>FA line 4</AddressLine4>
                  <Foreign>true</Foreign>
               </Address>
            </ProtectedAddresses>
         </MNProtectionOrderPartyAdditional>
      </ProtectionOrderParty>
   </ProtectionOrderParties>
   <MNProtectionOrderAdditional InternalID="2567" xmlns:fn="http://www.w3.org/2005/xpath-functions">
      <Conditions>
         <Condition>
            <Code Word="03AEXPC">03.A Respondent must not commit domestic abuse</Code>
            <Description>Respondent must not commit acts of domestic abuse against the Protected Person(s). </Description>
         </Condition>
         <Condition>
            <Code Word="03F1EXPC">03.F.1 Respondent must not call/enter place of employment</Code>               <Description>Respondent must not call or enter the place of employment of the following party(ies). This includes all land, parking lots, and buildings of the following addresses:</Description>
            <Parties>
               <Party InternalPartyID="1614451562"/>
               <Party InternalPartyID="1614451515"/>
            </Parties>
            <Addresses>
               <Address InternalAddressID="1618211271"/>
               <Address InternalAddressID="1618211278"/>
            </Addresses>
         </Condition>
         </Conditions>
      </MNProtectionOrderAdditional>
   </ProtectionOrder>


My xslt code for the conditions

Code: Select all

<!--ext:ProtectionOrderCondition-->
<xsl:for-each select="MNProtectionOrderAdditional/Conditions/Condition">
<ext:ProtectionOrderCondition>
<ext:ConditionText>
<xsl:variable name="vCondition">
<xsl:value-of select="normalize-space(Description)"/>
<xsl:text> </xsl:text>
<xsl:for-each select="Parties/Party">
<xsl:for-each select="ancestor::ProtectionOrder/ProtectionOrderParties/ProtectionOrderParty[@InternalPartyID=current()/@InternalPartyID]">
<xsl:value-of select="ProtectionOrderPartyNames/ProtectionOrderPartyName[@Current='true']/@FormattedName"/>
<!--<xsl:text>; </xsl:text>-->
<xsl:if test="position() != last()">
<xsl:text>; </xsl:text>
</xsl:if>
</xsl:for-each>
</xsl:for-each>
<xsl:text> </xsl:text>
<xsl:for-each select="Addresses/Address">
<xsl:for-each select="ancestor::ProtectionOrder/ProtectionOrderParties/ProtectionOrderParty/MNProtectionOrderPartyAdditional/ProtectedAddresses/Address[@InternalAddressID=current()/@InternalAddressID]">
<xsl:if test="AddressLine1">
<xsl:value-of select="AddressLine1"/>
<xsl:text>, </xsl:text>
</xsl:if>
<xsl:if test="AddressLine2">
<xsl:value-of select="AddressLine2"/>
<xsl:text>, </xsl:text>
</xsl:if>
<xsl:if test="AddressLine3">
<xsl:value-of select="AddressLine3"/>
<xsl:text>, </xsl:text>
</xsl:if>
<xsl:if test="AddressLine4">
<xsl:value-of select="AddressLine4"/>
</xsl:if>
<xsl:text>; </xsl:text>
</xsl:for-each>
</xsl:for-each>
</xsl:variable>
<xsl:choose>
<xsl:when test="substring($vCondition,string-length($vCondition)-1,2)='; '">
<xsl:value-of select="substring($vCondition,1,string-length($vCondition)-2)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$vCondition"/>
</xsl:otherwise>
</xsl:choose>
</ext:ConditionText>
<ext:ConditionCode>
<xsl:value-of select="document(concat($gEnvPath,'\ConfigFiles\MNCISCodes\ProtectionOrderConditionCodeMapping.xml'))
   /ProtectionOrderConditionCodeMapping/Mapping[MNCISCode=current()/Code/@Word]/BCACode"/>
</ext:ConditionCode>
</ext:ProtectionOrderCondition>
</xsl:for-each>
adrian
Posts: 2336

Re: How do I remove a semi colon when I have only one party

Tue Dec 30, 2014 5:44 pm

Hi,

I may have misunderstood but, you say you want the name followed by an address and then a semicolon and so on for each name/address pair, but your current stylesheet lists all the names and then lists all the addresses, so they are not paired like you said you need them. In other words, the extra semicolon seems to be the least of your worries, you first need to correctly pair each name/address.

You haven't mentioned which is the rule for pairing a name to an address.
I see that a ProtectionOrderParty has a ProtectionOrderPartyNames element which in turn has a ProtectionOrderPartyName and the ProtectionOrderParty also has a MNProtectionOrderPartyAdditional that has ProtectedAddresses with an Address. Does the ProtectionOrderParty define the pairing between names and adresses, or is the pairing from Condition of Parties/Party with Addresses/Address (first Party to first Address and so on)?


PS: If you don't want a trailing semicolon, make sure you compare the position() with the last() (<xsl:if test="position() != last()">) in the correct context. So you need to move it outside of the nested xsl:for-each and into the Parties/Party xsl:for-each. But like I said, first you need to address the pairing/structure.

Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
winkimjr2
Posts: 53

Re: How do I remove a semi colon when I have only one party

Tue Dec 30, 2014 8:54 pm

I used the code example you gave me to place the semi colon after the first name if there is more than one name and this solved that problem.
As for the address and name, I will confirm what format is needed. As for now, I will just leave it the way it is.
Thanks for your help Adrian.

Return to “XSLT and FOP”

Who is online

Users browsing this forum: No registered users and 0 guests