我有几个CaseParties的xml代码。我想只为受访者显示ObservedEthnicity。我的xslt正在显示ObservedEthnicity,但是对于第一个找到的CaseParty。 如何更改它以显示受访者的ObservedEthnicity? 这是我的xml代码
<Integration xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:tsg="http://tsgweb.com" xmlns:IXML="http://tsgweb.com">
<Case InternalID="1616760296" ID="11683548" xmlns:user="http://tylertechnologies.com">
<CaseParty ID="16548426" InternalCasePartyID="1633585331" InternalPartyID="1614451562">
<ObservedRace Word="W">White</ObservedRace>
<ObservedEthnicity Word="NH">Non Hispanic</ObservedEthnicity>
<Connection Word="PET" BaseConnection="PL" ID="34645653" InternalCasePartyConnectionID="1635192840">
<Description>Petitioner</Description>
</Connection>
<CasePartyName Current="true" ID="9638953" InternalNameID="1615263003">
<FormattedName>Petitioner, Richard S</FormattedName>
</CasePartyName>
</CaseParty>
<CaseParty ID="16548378" InternalCasePartyID="1633585333" InternalPartyID="1614451515">
<ObservedRace Word="W">White</ObservedRace>
<ObservedEthnicity Word="R">Refused</ObservedEthnicity>
<Connection Word="CHL" BaseConnection="WA" ID="34645655" InternalCasePartyConnectionID="1635192842">
<Description>Child (Family/Juv)</Description>
</Connection>
<CasePartyName Current="true" ID="9638891" InternalNameID="1615262953">
<FormattedName>Dickens, Little</FormattedName>
</CasePartyName>
</CaseParty>
<CaseParty ID="16548427" InternalCasePartyID="1633585332" InternalPartyID="1614451563">
<ObservedRace Word="W">White</ObservedRace>
<ObservedEthnicity Word="H">Hispanic</ObservedEthnicity>
<Connection Word="RSP" BaseConnection="DF" ID="34645654" InternalCasePartyConnectionID="1635192841">
<Description>Respondent</Description>
</Connection>
<CasePartyName Current="true" ID="9638954" InternalNameID="1615263004">
<FormattedName>Respondent, Richard S</FormattedName>
</CasePartyName>
</CaseParty>
</Case>
这是我的xslt代码
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ext="http://www.courts.state.dc.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">
<ext:ProtectionOrder>
<xsl:variable name="vProtectionOrderID">
<xsl:value-of select="@InternalProtectionOrderID"/>
</xsl:variable>
<!--Respondent Address-->
<xsl:for-each select="RespondentAddresses/Address">
<xsl:call-template name="Location"/>
</xsl:for-each>
<!--ext:ProtectionOrderID-->
<ext:ProtectionOrderID>
<xsl:value-of select="ProtectionOrderNumber"/>
</ext:ProtectionOrderID>
<!--Respondent-->
<xsl:for-each select="RespondentPartyID">
<xsl:for-each select="//CaseParty[(@InternalPartyID=current()/@InternalPartyID) and (Connection[(@Word='RSP') ])]">
<xsl:for-each select="//Party[@InternalPartyID=current()/@InternalPartyID]">
<xsl:call-template name="Respondent">
<xsl:with-param name="pProtectionOrderID">
<xsl:value-of select="$vProtectionOrderID"/>
</xsl:with-param>
</xsl:call-template>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
</ext:ProtectionOrder>
</xsl:template>
<!--Respondent Template-->
<xsl:template name="Respondent">
<xsl:param name="pProtectionOrderID"/>
<ext:Respondent>
<nc:PersonEthnicityCode>
<xsl:choose>
<xsl:when test="//CaseParty[@ID=current()/@ID]/ObservedEthnicity/@Word='NH'">N</xsl:when>
<xsl:otherwise>
<xsl:if test="//CaseParty/ObservedEthnicity[@Word!='R']">
<xsl:value-of select="//CaseParty/ObservedEthnicity/@Word"/>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
</nc:PersonEthnicityCode>
</ext:Respondent>
<ext:RespondentPresentAtHearingIndicator>
<xsl:value-of select="/Integration/ProtectionOrder/MNProtectionOrderAdditional/IsRespondentPresent"/>
</ext:RespondentPresentAtHearingIndicator>
</xsl:template>
</xsl:stylesheet>
答案 0 :(得分:0)
我想为受访者展示ObservedEthnicity。我的xslt正在显示ObservedEthnicity,但对于第一个CaseParty,它恰好不是被回答者。如何更改代码以显示被调查者的ObservedEthnicity,无论被调查者在哪里?
答案 1 :(得分:0)
这就是我为获得想要的输出所做的。但是我现在想要改变它,所以如果xml具有带R的以下元素,则它不应该显示。
<ObservedEthnicity Word="R">Refused</ObservedEthnicity>
xml中观察到的种族与xslt中的PersonEthnicityCode相同
在这种情况下,我不想显示它。这反映在我的xslt
中<nc:PersonEthnicityCode>
<xsl:choose>
<xsl:when test="//CaseParty[@ID=current()/@ID]/ObservedEthnicity/@Word='NH'">N</xsl:when>
<xsl:otherwise>
<xsl:value-of select="//CaseParty/ObservedEthnicity/@Word"/>
</xsl:otherwise>
</xsl:choose>
</nc:PersonEthnicityCode>
我做了什么xslt代码(一行)
<nc:PersonEthnicityCode>
<xsl:choose>
<xsl:when test="//CaseParty[@ID=current()/@ID]/ObservedEthnicity/@Word='NH'">N</xsl:when>
<xsl:otherwise>
<xsl:value-of select="//CaseParty/ObservedEthnicity/@Word"/>
</xsl:otherwise>
</xsl:choose>
</nc:PersonEthnicityCode>
答案 2 :(得分:0)
看起来你需要放一个xsl:if在nc:PersonEthnicityCode周围。类似的东西:
<!-- assume exactly one ObservedEthnicity -->
<!-- Significance of ObservedEthnicity's text() nodes not clear; just using @Word. -->
<xsl:variable name="observed-ethnicity-word"
select="//CaseParty[@ID=current()/@ID]/ObservedEthnicity/@Word">
<xsl:if test"$observed-ethnicity-word != 'R'">
<nc:PersonEthnicityCode>
<xsl:choose>
<xsl:when test="$observed-ethnicity-word = 'NH'">N</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$observed-ethnicity-word"/>
</xsl:otherwise>
</xsl:choose>
</nc:PersonEthnicityCode>
</xsl:if>