如何仅根据最低的InternalPartyID显示一个元素而不是两个元素?

时间:2014-12-22 21:09:05

标签: xml xslt

如何在申请人模板上使用 If Statement 来检查是否有其他请愿者的@InternalPartyID较低且petitionerindicator的标志设置为true,如此<ext:PetitionerIndicator>true</ext:PetitionerIndicator>。 如果有,那么选择具有最低@InternalPartyID的那个,如果没有,则选择这个。这是因为当有多个请愿者时,企业要我选择具有最低@InternalPartyID的请愿者。

当前输出显示请愿者指示符= true的2个请愿者:我只想根据请愿者的最低值@InternalPartyID显示2个中的一个。

<ext:ProtectedParty>
        <ext:PersonBirthDate ext:approximateDateIndicator="false" ext:currentIndicator="true">1969-08-06</ext:PersonBirthDate>
        <nc:PersonName>
            <nc:PersonGivenName>MARY</nc:PersonGivenName>
            <nc:PersonMiddleName/>
            <nc:PersonSurName>TESTER</nc:PersonSurName>
            <nc:PersonNameSuffixText/>
            <nc:PersonFullName>TESTER, MARY</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:PersonGivenName>Mary</nc:PersonGivenName>
            <nc:PersonMiddleName/>
            <nc:PersonSurName>Verify</nc:PersonSurName>
            <nc:PersonNameSuffixText/>
            <nc:PersonFullName>Verify, Mary</nc:PersonFullName>
        </nc:PersonName>
        <ext:PersonRaceCode/>
        <nc:PersonSexCode>F </nc:PersonSexCode>
        <ext:PetitionerIndicator>true</ext:PetitionerIndicator>
    </ext:ProtectedParty>

所需的输出:具有最低的InternalPartyID 1614450397

<ext:ProtectedParty>
        <ext:PersonBirthDate ext:approximateDateIndicator="false" ext:currentIndicator="true">1978-08-01</ext:PersonBirthDate>
        <nc:PersonName>
            <nc:PersonGivenName>Mary</nc:PersonGivenName>
            <nc:PersonMiddleName/>
            <nc:PersonSurName>Verify</nc:PersonSurName>
            <nc:PersonNameSuffixText/>
            <nc:PersonFullName>Verify, Mary</nc:PersonFullName>
        </nc:PersonName>
        <ext:PersonRaceCode/>
        <nc:PersonSexCode>F </nc:PersonSexCode>
        <ext:PetitionerIndicator>true</ext:PetitionerIndicator>
    </ext:ProtectedParty>

xml代码

<Integration xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:tsg="http://tsgweb.com" xmlns:IXML="http://tsgweb.com" xmlns:CMCodeQueryHelper="urn:CMCodeQueryHelper" PackageID="BCA PO Notification" MessageID="57825599" xmlns="">
    <ControlPoint Timestamp="12/8/2014 2:46:15 PM" UserID="SkillingJ">SAVE-PROTECTION-ORDER</ControlPoint>
    <Case InternalID="1616756492" ID="11678589" xmlns:user="http://tylertechnologies.com">
        <CaseParty ID="2172461" InternalCasePartyID="1633578953" InternalPartyID="280365977">
            <Connection Word="PET" BaseConnection="PL" ID="34638600" InternalCasePartyConnectionID="1635186366">
                <Description>Petitioner</Description>
            </Connection>
            <CasePartyName Current="true" ID="1525998" InternalNameID="280365977">
                <NameType>Standard</NameType>
                <NameFirst>MARY</NameFirst>
                <NameLast>TESTER</NameLast>
                <FormattedName>TESTER, MARY</FormattedName>
            </CasePartyName>
        </CaseParty>
        <CaseParty ID="16547264" InternalCasePartyID="1633580396" InternalPartyID="1614450397">
            <SendNotice>true</SendNotice>
            <Connection Word="PET" BaseConnection="PL" ID="34640256" InternalCasePartyConnectionID="1635187864">
                <Description>Petitioner</Description>
            </Connection>
            <CasePartyName Current="true" ID="9637412" InternalNameID="1615261753">
                <NameType>Standard</NameType>
                <NameFirst>Mary</NameFirst>
                <NameLast>Verify</NameLast>
                <FormattedName>Verify, Mary</FormattedName>
            </CasePartyName>
        </CaseParty>
        <ProtectionOrders>
            <ProtectionOrder Op="E" InternalProtectionOrderID="1373">
                <Deleted>false</Deleted>
                <ProtectionOrderNumber>1400374</ProtectionOrderNumber>
                <ProtectionOrderParties>
                    <ProtectionOrderParty InternalPartyID="280365977">
                        <ProtectionOrderPartyNames>
                            <ProtectionOrderPartyName Current="true" InternalNameID="280365977" FormattedName="TESTER, MARY"/>
                        </ProtectionOrderPartyNames>
                        <Added>12/3/2014</Added>
                        <ProtectionOrderConnection>
                            <Petitioner>true</Petitioner>
                            <FilingParty>false</FilingParty>
                            <ProtectedParty>true</ProtectedParty>
                            <Minor>false</Minor>
                        </ProtectionOrderConnection>
                    </ProtectionOrderParty>
                    <ProtectionOrderParty InternalPartyID="1614450397">
                        <ProtectionOrderPartyNames>
                            <ProtectionOrderPartyName Current="true" InternalNameID="1615261753" FormattedName="Verify, Mary"/>
                        </ProtectionOrderPartyNames>
                        <Added>12/3/2014</Added>
                        <ProtectionOrderConnection>
                            <Petitioner>true</Petitioner>
                            <FilingParty>false</FilingParty>
                            <ProtectedParty>true</ProtectedParty>
                            <Minor>false</Minor>
                        </ProtectionOrderConnection>
                    </ProtectionOrderParty>
                </ProtectionOrderParties>
            </ProtectionOrder>
        </ProtectionOrders>
    </Case>
    <Party ID="2172461" InternalPartyID="280365977">
        <DateOfBirth Current="true">08/06/1969</DateOfBirth>
        <PartyName ID="1525998" Current="true" InternalNameID="280365977">
            <NameType>Standard</NameType>
            <NameFirst>MARY</NameFirst>
            <NameLast>TESTER</NameLast>
            <FormattedName>TESTER, MARY</FormattedName>
        </PartyName>
    </Party>
    <Party ID="16547264" InternalPartyID="1614450397">
        <DateOfBirth Current="true">08/01/1978</DateOfBirth>
        <PartyName ID="9637412" Current="true" InternalNameID="1615261753">
            <NameType>Standard</NameType>
            <NameFirst>Mary</NameFirst>
            <NameLast>Verify</NameLast>
            <FormattedName>Verify, Mary</FormattedName>
        </PartyName>
    </Party>
    <ProtectionOrder Op="E" InternalProtectionOrderID="1373" xmlns:user="http://tylertechnologies.com">
        <ProtectionOrderNumber>1400374</ProtectionOrderNumber>
        <ProtectionOrderParties>
            <ProtectionOrderParty InternalPartyID="280365977">
                <ProtectionOrderPartyNames>
                    <ProtectionOrderPartyName Current="true" InternalNameID="280365977" FormattedName="TESTER, MARY"/>
                </ProtectionOrderPartyNames>
                <ProtectionOrderConnection>
                    <Petitioner>true</Petitioner>
                    <FilingParty>false</FilingParty>
                    <ProtectedParty>true</ProtectedParty>
                    <Minor>false</Minor>
                </ProtectionOrderConnection>
            </ProtectionOrderParty>
            <ProtectionOrderParty InternalPartyID="1614450397">
                <ProtectionOrderPartyNames>
                    <ProtectionOrderPartyName Current="true" InternalNameID="1615261753" FormattedName="Verify, Mary"/>
                </ProtectionOrderPartyNames>
                <ProtectionOrderConnection>
                    <Petitioner>true</Petitioner>
                    <FilingParty>false</FilingParty>
                    <ProtectedParty>true</ProtectedParty>
                    <Minor>false</Minor>
                </ProtectionOrderConnection>
            </ProtectionOrderParty>
        </ProtectionOrderParties>
    </ProtectionOrder>
<IntegrationConditions>
        <IntegrationCondition Word="BCAPO" Description="BCA PO Notification">
            <NotificationEvent internalProtectionOrderID="1373" protectionOrderNumber="1400374"</NotificationEvent>
        </IntegrationCondition>
    </IntegrationConditions>
</Integration>

xslt代码

    <xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ext="http://www.courts.state.mn.us/ProtectionOrderExtension/1.0" xmlns:nc="http://niem.gov/niem/niem-core/2.0">
    <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
    <xsl:template name="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>
<!--Protected Party -->
            <xsl:for-each select="ProtectionOrderParties/ProtectionOrderParty[ProtectionOrderConnection/ProtectedParty='true']">
                <xsl:variable name="vPetitionerIndicator">
                    <xsl:value-of select="ProtectionOrderConnection/Petitioner"/>
                </xsl:variable>
                <xsl:for-each select="//CaseParty[(@InternalPartyID=current()/@InternalPartyID)]">
                    <xsl:for-each select="/Integration/Party[@InternalPartyID=current()/@InternalPartyID]">
                        <xsl:call-template name="ProtectedParty">
                            <xsl:with-param name="pPetionerIndicator">
                                <xsl:value-of select="$vPetitionerIndicator"/>
                            </xsl:with-param>
                        </xsl:call-template>
                    </xsl:for-each>
                </xsl:for-each>
            </xsl:for-each>
    </xsl:template>
<!--Petitioner Template-->
    <xsl:template name="Petitioner">
        <ext:Petitioner>
            <nc:PersonName>
                <nc:PersonFullName>
                    <xsl:value-of select="PartyName/FormattedName"/>
                </nc:PersonFullName>
            </nc:PersonName>
        </ext:Petitioner>
    </xsl:template>
</xsl:stylesheet>

2 个答案:

答案 0 :(得分:1)

  

我有一个包含2个请愿者的xml文档。我只想显示一个   它们基于请愿人的最低值@InternalPartyID。

通过InternalPartyID升序对请愿者进行排序,并获取结果集中的第一个。


例如,给出以下测试输入

<Integration>
    <Case>
        <CaseParty InternalPartyID="280365977">
            <CasePartyName>
                <NameFirst>MARY</NameFirst>
                <NameLast>TESTER</NameLast>
            </CasePartyName>
        </CaseParty>
        <CaseParty InternalPartyID="1614450397">
            <CasePartyName>
                <NameFirst>Mary</NameFirst>
                <NameLast>Verify</NameLast>
            </CasePartyName>
        </CaseParty>
    </Case>
</Integration>

以下样式表

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

<xsl:template match="/Integration">
    <output>
        <xsl:apply-templates select="Case/CaseParty">
            <xsl:sort select="@InternalPartyID" data-type="number" order="ascending"/>
        </xsl:apply-templates>
    </output>
</xsl:template>

<xsl:template match="CaseParty">
    <xsl:if test="position() = 1">
        <ProtectedParty>
            <PersonName>
                <PersonGivenName><xsl:value-of select="CasePartyName/NameFirst"/></PersonGivenName>
                <PersonSurName><xsl:value-of select="CasePartyName/NameLast"/></PersonSurName>
            </PersonName>
        </ProtectedParty>
    </xsl:if>
</xsl:template>

</xsl:stylesheet>

将返回:

<?xml version="1.0" encoding="UTF-8"?>
<output>
  <ProtectedParty>
    <PersonName>
      <PersonGivenName>Mary</PersonGivenName>
      <PersonSurName>Verify</PersonSurName>
    </PersonName>
  </ProtectedParty>
</output>

答案 1 :(得分:0)

我决定将请求者设置为true的ProtectionOrderParties计算在内。如果我找到任何其他ProtectedOrderParties,那么我检查他们的@InternalPartyID是否低于当前的。 这解决了我的问题。 我要感谢Michael对此的帮助。

xslt代码解决方案:

<xsl:if test="count(../ProtectionOrderParty[(ProtectionOrderConnection/Petitioner='true') and (@InternalPartyID&lt;current()/@InternalPartyID)])=0">