如何查找和显示CaseParty地址?

时间:2015-06-03 22:36:11

标签: xml xslt

我想在下面的xml文档中循环,并显示{地址} /Integration/Case/CaseParty/Address /Integration/Case/CaseParty/Connection[@Word="DFD"]

如果在/Integration/Case/CaseParty/Address找不到CaseParty/Connection[@Word="DFD"],我想查看PartyID/Integration/Party/Address[@PartyCurrent="true"]下的地址并显示该地址。

这是我的xml文档

<Integration xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:tsg="http://tsgweb.com" xmlns:IXML="http://tsgweb.com" xmlns:CMCodeQueryHelper="urn:CMCodeQueryHelper" PackageID="DL Notice to DVS" MessageID="67084533" xmlns="">
<Case Op="E" InternalID="1617088326" ID="12120229" xmlns:user="http://tylertechnologies.com">
    <CaseParty ID="16731290" InternalCasePartyID="1634787102" InternalPartyID="1614631672">
        <Connection Word="DFD" BaseConnection="DF" ID="36370323" InternalCasePartyConnectionID="1636469444">
            <Description>Defendant</Description>
        </Connection>
        <Address CaseCorrespondence="true" ID="17875824" Type="Standard">
            <AddressLine2>3712 Testing RD</AddressLine2>
            <AddressLine4>St Paul, NY, 21457</AddressLine4>
            <Block>3712</Block>
            <Street>Testing</Street>
            <AddrSfxKy Word="RD">Road</AddrSfxKy>
            <City>St Paul</City>
            <State>NY</State>
            <Zip>21457</Zip>
            <Foreign>false</Foreign>
            <TimestampCreate>5/27/2015 10:34:08 AM</TimestampCreate>
        </Address>
        <TimestampCreate>1/29/2015 5:04:53 PM</TimestampCreate>
        <TimestampChange/>
    </CaseParty>
</Case>
<Party ID="16731290" InternalPartyID="1614631672">
    <Address PartyCorrespondence="true" PartyCurrent="true" ID="17867956" Type="Standard">
        <AddressLine2>1906 3RD AVE S #36</AddressLine2>
        <AddressLine4>Denver, CO, 55408</AddressLine4>
        <Block>1906</Block>
        <Street>3RD AVE S #36</Street>
        <City>Denver</City>
        <State>CO</State>
        <Zip>87459</Zip>
        <Foreign>false</Foreign>
    </Address>
</Party>

所需的输出应该是纽约地址。

我不确定如何检查来自xpath /Integration/Case/CaseParty/Address/Integration/Party/Address

的地址

xsl代码。

<xsl:value-of Select="/Integration/Case/CaseParty/Connection[@Word="DFD"]/Address"/>

2 个答案:

答案 0 :(得分:1)

XPath返回一个节点集(或者可能没有),在你的情况下将它们联合在一起以选择一个。考虑这样的选择:

rule1 |规则2 [否(规则1)]

如果它通过,你将总是得到rule1,或者如果它通过则会得到rule2,如果两者都不通过,你将总是得到。

rule1 = / Integration / Case / CaseParty / Address [preceding-sibling :: Connection [@Word =&#39; DFD&#39;]]

rule2 = /整合/聚会/地址[@PartyCurrent =&#39; true&#39;]

(/Integration/Case/CaseParty/Address[preceding-sibling::Connection[@Word='DFD']] | /Integration/Party/Address[@PartyCurrent='true'][not(/Integration/Case/CaseParty/Address[preceding-sibling::Connection[@Word='DFD']])])[1]

请注意,我在最后添加了[1]谓词,因为我不知道在每种情况下是否可以有多个地址。只有在数据中可以使用它才能返回多个节点时才需要它。

答案 1 :(得分:1)

一个简单的,如果详细的方法是使用xsl:choose,方法如下:

<xsl:variable name="primary-address" select="path/to/primary/address" />
<xsl:choose>
    <xsl:when test="$primary-address">
        <xsl:value-of select="$primary-address"/>
    </xsl:when>
    <xsl:otherwise>
        <xsl:value-of select="path/to/secondary/address"/>
    </xsl:otherwise>
</xsl:choose>

或在XSLT 2.0中:

<xsl:variable name="primary-address" select="path/to/primary/address" />
<xsl:value-of select="if($primary-address) then $primary-address else path/to/secondary/address"/>