【发布时间】:2014-10-28 16:51:33
【问题描述】:
我的 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中进行什么更改,以便只在有多个名称时插入分号,而在只有一个名称时不插入分号?
【问题讨论】:
-
请同时显示您的 XML 输入文档 - 以及更多 XSLT 代码,最好是完整的工作样式表。
-
在您的代码中,决定何时输出分号的逻辑位于 inner
for-each内部,因此它正在检查ProtectionOrderParty列表中与当前匹配的位置InternalPartyID,不在Parties/Party的列表中。没有看到 XML 我不能确定,但它肯定看起来很可疑。