我的输出显示了两方之间的半冒号,但也有一方

时间:2014-10-28 16:51:33

标签: xml xslt

我的xml代码可以在条件文本中包含一个或多个参与方。当有多个聚会时,则在两个聚会名称之间插入一个分号。如果只有一方,则名称末尾不需要分号。 当我的xml文档有2个聚会时,我的xslt正常工作但是当只有一个聚会时它仍然添加了一个半冒号。 当xml文档有多方时,如何只显示半冒号?当xml文档有一方时,如何不显示半冒号?

以下是2方的输出,这是我想要的名称(方)之间的半冒号:但地址是乱序的。每个参与方的名称后面都应该是其地址,然后是一个分号,然后是另一个名称,地址和句点结尾。

<ext:ProtectionOrderCondition>
        <ext:ConditionText>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: Petitioner, Richard S; Dickens, Little;  3 Back Petitioner ST, My Town, MN, 55555; Foreign Address, FA line 2, FA line 3, FA line 4</ext:ConditionText>
        <ext:ConditionCode>04</ext:ConditionCode>
    </ext:ProtectionOrderCondition>

当xml文档只有一方时,这是我的输出。请注意,末尾有一个半结肠,不应该存在:

<ext:ProtectionOrderCondition>
        <ext:ConditionText>Petitioner is awarded sole physical and legal custody of the following child(ren): Brown, Rayne;  </ext:ConditionText>
        <ext:ConditionCode>09</ext:ConditionCode>
    </ext:ProtectionOrderCondition>

我的xml代码与一方

            <ProtectionOrder Op="E" InternalProtectionOrderID="2563">
            <ProtectionOrderParties>
                <ProtectionOrderParty InternalPartyID="1614450754">
                    <ProtectionOrderPartyNames>
                        <ProtectionOrderPartyName Current="true" InternalNameID="1615262152" FormattedName="Brown, Rayne"/>
                    </ProtectionOrderPartyNames>
                    <Added>12/29/2014</Added>
                    <ProtectionOrderConnection>
                        <Petitioner>true</Petitioner>
                        <FilingParty>false</FilingParty>
                        <ProtectedParty>true</ProtectedParty>
                        <Minor>false</Minor>
                    </ProtectionOrderConnection>
                    <MNProtectionOrderPartyAdditional xmlns:fn="http://www.w3.org/2005/xpath-functions">
                        <DoesResideWithRespondent>false</DoesResideWithRespondent>
                        <ProtectedAddresses>
                            <Address InternalAddressID="1618211259" Type="Standard">
                                <Location Word="HOME">Home</Location>
                                <Confidential>false</Confidential>
                                <AddressLine2>1048 Regions RD</AddressLine2>
                                <AddressLine4>St Paul, MN, 55101</AddressLine4>
                                <Block>1048</Block>
                                <Street>Regions</Street>
                                <AddrSfxKy Word="RD">Road</AddrSfxKy>
                                <City>St Paul</City>
                                <State>MN</State>
                                <Zip>55101</Zip>
                                <Foreign>false</Foreign>
                                <TimestampCreate>12/29/2014 08:14:22:787</TimestampCreate>
                            </Address>
                        </ProtectedAddresses>
                    </MNProtectionOrderPartyAdditional>
                </ProtectionOrderParty>
            </ProtectionOrderParties>

            <MNProtectionOrderAdditional InternalID="2559" xmlns:fn="http://www.w3.org/2005/xpath-functions">
                <Conditions>
                    <Condition>
                        <Code Word="04AOAHC">04.A Respondent shall not call/enter place of employment</Code>
                        <Description>Respondent shall not call or enter Petitioner's place of employment which includes all land, parking lots, and buildings at:</Description>
                        <Addresses>
                            <Address InternalAddressID="1618211259"/>
                        </Addresses>
                    </Condition>
                    <Condition>
                        <Code Word="05OAHC">05 Petitioner is awarded sole physical and legal custody</Code>
                        <Description>Petitioner is awarded sole physical and legal custody of the following child(ren):</Description>
                        <Parties>
                            <Party InternalPartyID="1614450754"/>
                        </Parties>
                    </Condition>
                </Conditions>
            </MNProtectionOrderAdditional>
        </ProtectionOrder>

我的xml文档包含两方:

<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>
            <Added>12/29/2014</Added>
            <ProtectionOrderConnection>
                <Petitioner>true</Petitioner>
                <FilingParty>false</FilingParty>
                <ProtectedParty>true</ProtectedParty>
                <Minor>false</Minor>
            </ProtectionOrderConnection>
            <MNProtectionOrderPartyAdditional xmlns:fn="http://www.w3.org/2005/xpath-functions">
                <DoesResideWithRespondent>false</DoesResideWithRespondent>
                <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>
                        <TimestampCreate>12/29/2014 10:11:36:903</TimestampCreate>
                    </Address>
                </ProtectedAddresses>
            </MNProtectionOrderPartyAdditional>
        </ProtectionOrderParty>
        <ProtectionOrderParty InternalPartyID="1614451515">
            <ProtectionOrderPartyNames>
                <ProtectionOrderPartyName Current="true" InternalNameID="1615262953" FormattedName="Dickens, Little"/>
            </ProtectionOrderPartyNames>
            <Added>12/29/2014</Added>
            <ProtectionOrderConnection>
                <Petitioner>false</Petitioner>
                <FilingParty>false</FilingParty>
                <ProtectedParty>true</ProtectedParty>
                <Minor>true</Minor>
            </ProtectionOrderConnection>
            <MNProtectionOrderPartyAdditional xmlns:fn="http://www.w3.org/2005/xpath-functions">
                <DoesResideWithRespondent>false</DoesResideWithRespondent>
                <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>
                        <TimestampCreate>12/29/2014 11:49:37:020</TimestampCreate>
                    </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). This means that Respondent may not harm or cause fear of harm to the Protected Person(s), and that Respondent may not use, attempt to use, or threaten to use physical force that would reasonably be expected to cause bodily injury to 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>

我的xslt代码

<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>

我需要在xslt中更改什么才能仅在有多个名称时插入分号,而在只有一个名称时才插入?

1 个答案:

答案 0 :(得分:1)

标准习语是而不是

<xsl:text>; </xsl:text>

<强> 使用

<xsl:if test="position() != last()">
     <xsl:text>; </xsl:text>
</xsl:if>