2014-12-29 2 views
-3

내 xml 코드에 조건 노드 주소와 파티 요소가 있으면 세미콜론이 파티 이름 뒤에 추가됩니다. 이후 아무 것도 없기 때문에 세미 콜론의 이름 뒤에 아무 것도 입력하고 싶지 않습니다. ** 1048 지역 RD, 세인트 폴, 브라운, 레인 ** :텍스트 조각 사이에 세미콜론을 추가하지만 텍스트 조각의 끝에는 어떻게 삽입합니까?

다음과 같이 고용의 다음 장소 (들)에서 다음 자 (들)에 대한 신청인의 접근이 제한됩니다 다음은 출력 단 하나의 파티 이름이 비록 내 출력 조건 텍스트 요소의 끝에 세미콜론을 표시하고 여기에

55,101 MN. 하나의 파티 이름이있을 때 세미콜론이 표시되지 않도록 xslt를 어떻게 변경합니까?

청원 자에게는 다음 아동 (들)의 유일한 신체적 법적 보호가 부여됩니다. 09

내 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="57832809" xmlns=""> 
     <ProtectionOrder Op="E" InternalProtectionOrderID="2563" xmlns:user="http://tylertechnologies.com"> 
      <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> 
        <MNProtectionOrderAdditional InternalID="2604" xmlns:fn="http://www.w3.org/2005/xpath-functions"> 
      <Conditions> 
       <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="1614450754"/> 
        </Parties> 
        <Addresses> 
         <Address InternalAddressID="1618211350"/> 
        </Addresses> 
       </Condition> 
       <Condition> 
        <Code Word="03F2EXPC">03.F.2 Respondent's access at place of employment</Code> 
        <Description>Respondent's access to the following party(ies) at the following place(s) of employment is limited as follows: </Description> 
        <Parties> 
         <Party InternalPartyID="1614450754"/> 
        </Parties> 
        <Addresses> 
         <Address InternalAddressID="1618211350"/> 
        </Addresses> 
       </Condition> 
      </Conditions> 
     </MNProtectionOrderAdditional> 
       </ProtectionOrderParty> 
      </ProtectionOrderParties> 
      <MNProtectionOrderAdditional InternalID="2559" xmlns:fn="http://www.w3.org/2005/xpath-functions"> 
       </xsl:if>   
</MNProtectionOrderAdditional> 
     </ProtectionOrder> 
</Integration> 

내 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 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.mn.us/ProtectionOrderExtension/1.0"> 
    <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> 
    <xsl:template name="ProtectionOrder"> 
     <ext:ProtectionOrder> 
<!--ext:ProtectionOrderCondition--> 
      <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:for-each> 
            <xsl:if test="position() != last()"> 
            <xsl:text>; </xsl:text> 
            </xsl:if> 
          </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> 
     </ext:ProtectionOrder> 
    </xsl:template> 
</xsl:stylesheet> 
+2

는 "* 나는 사람들이 이전이 해결되었습니다 생각하는 것처럼 보이기 때문에 새 게시물을 게시하기로 결정했다. *"그렇게하지 마십시오. –

+0

당신의 조언은 무엇입니까? 그 중 하나를 삭제해야합니까? – user3781064

+2

최근에 많은 질문에 downvote 만 받았고 많은 혼란을 겪었습니까? 한 걸음 물러서서 XSLT의 기초를 살펴볼 시간입니다. [좋은 질문 샘플을 만드는 법]에서 [SO 질문에 대한 기본 사항] (http://stackoverflow.com/help/how-to-ask) _and_ (http://stackoverflow.com/help/mcve). –

답변

0

어쩌면 오해가 있지만, 같은 작동하지 않을 요청이있는 경우이

<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:if test="position() = last()"> 
     <xsl:text>; </xsl:text> 
     </xsl:if> 
    </xsl:for-each> 
</xsl:for-each> 

그냥으로 변경됩니다 :

<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:if test="position() != last()"> 
     <xsl:text>; </xsl:text> 
     </xsl:if> 
    </xsl:for-each> 
</xsl:for-each> 

는 현재 ;은 마지막 요소 추가됩니다 (시 position() = last()를) ,하지만 난 당신이 복수의 당사자 (있는 경우) 사이에 그것을 가지고 싶습니다, 그래서 당신이 position() != last()로 변경하면 작동합니다.

업데이트 : 의견에서 언급했듯이 제안 된 방법은 의도 한대로 작동하지 않습니다. 입력 XML을 알고 있지만 언급처럼,이 파티 요소의 양을 기준으로해야하기 때문에이 일할 수있는 가정하지 : 각 후 ;를 작성해야

<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:for-each> 
    <xsl:if test="position() != last()"> 
     <xsl:text>; </xsl:text> 
    </xsl:if> 
</xsl:for-each> 

대신 내부 루프의 <xsl:for-each select="Parties/Party"><xsl:if test="position() != last()"> 문을 이동 Party이 마지막이 아닌 경우 Party입니다.

업데이트 : 의견에 언급 된 문제와 관련된 업데이트 된 질문 - 문제를 완전히 이해할 수 있는지 잘 모르겠습니다. 업데이트 된 XSLT는 다음과 같아야합니다. Party이 하나 이상인 경우 ;Party 사이에 추가됩니다 (position() != last() 사용).내가 이해하는 바와 같이 Party 이름 뒤에 ;이 있어야하며 그 뒤에는 Address이옵니다. 현재 party 요소가 하나 이상이라도 마지막으로 Party 이름 뒤에 ;이 표시되지 않습니다. 다음 접근 방식을 제안합니다. Address 노드를 계산하고 Party 요소의 위치가 last()이고 Address 인 지 확인하십시오. 이 경우, 변수 addressCount&gt; 0로 기록 > 0이다 (탈출) :이 ;Party 사이에 이름을 추가 마지막 Party (아니라면 ; 쓰기 :

<xsl:variable name="addressCount" select="count(Addresses/Address)"/> 
<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:for-each> 
    <xsl:if test="position() != last() or (position() = last() 
       and $addressCount &gt; 0)"> 
     <xsl:text>; </xsl:text> 
    </xsl:if> 
</xsl:for-each> 

수단

<xsl:if test="position() != last() or (position() = last() 
    and $addressCount &gt; 0)"> 
    <xsl:text>; </xsl:text> 
</xsl:if> 

사용 0보다 큰 경우 Party) 또는 인 경우 마지막 Party이고 Address 요소의 수는입니다..

+0

내가 겪고있는 문제는';'및 조건문에서 내 XML로 2 명의 당사자와 테스트, 나는 이름 사이에 세미 콜론을 얻지 못한다. 그러나, 내 XML 조건문에 단 하나의 파티가있을 때 세미 콜론이 이름 끝 부분에 추가됩니다.이 콜론은 원하는 것이 아닙니다. 내가 제거 할 때! 다음과 같이 코드를 남겨 둡니다. ;'xml에 2 개의 파티가있을 때 세미콜론이 추가되지만 xml에 파티가 하나 뿐인 경우 세미 콜론이 추가됩니다. – user3781064

+0

@ user3781064 방금 내 대답을 업데이트했습니다. 그래도 여전히 작동하지 않는다면 짐작할 만하다. 질문에 입력 된 것보다 더 많은 것이 더 좋을 것입니다. –

+0

고맙습니다. mathias_h. 파티 루프 밖에서 테스트 위치 문을 움직이면 효과가있었습니다! 다시 한 번 감사드립니다. 이제이 문제를 해결 된 것으로 표시하고 내 대답을 내 문제를 해결 한 올바른 방법으로 표시합니다. – user3781064

0

내가 제안한대로 여기에 각 문에 대한 코드를 이동합니다.

XSLT 코드는

<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:if test="position() = last()"> 
    <xsl:text>; </xsl:text> 
    </xsl:if> 
    </xsl:for-each> 
</xsl:for-each> 
관련 문제