2017-10-17 96 views
0

我的代碼是:我們必須從指定的路徑獲取描述。但是在Description1Name中發生重複;是否可以刪除重複?我已經找到了它,但是這不起作用。如何在xslt中的標記中複製值?

?xml version="1.0" encoding="utf-8"?> 
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl" 
> 
    <xsl:template match="/"> 
     <xsl:param name="text1" select="PFA/Description1List/Description1Name"/> 
     <xsl:param name="text2" select="PFA/Description2List/Description2Name"/> 
     <Entity_List Type="LIST_TYPE_CUSTOM_ENTITY" xmlns="https://support.bridgerinsight.lexisnexis.com/downloads/xsd/4.2/CWLEntityExport.xsd"> 
     <xsl:for-each select="PFA/Records/Person"> 
      <Entity> 
      <First_Name> 
       <xsl:value-of select="NameDetails/Name/NameValue/FirstName"/> 
      </First_Name> 
      <Reason_Listed> 
       <xsl:for-each select="Descriptions/Description" > 
       <xsl:variable name="check1" select="@Description1"></xsl:variable> 
       <xsl:variable name="check2" select="@Description2"></xsl:variable> 
       <!--<xsl:if test="index-of(temp, $check1)!=()">--> 
       <xsl:for-each select="$text1"> 
        <xsl:if test="[email protected]ription1Id"> 
        <xsl:value-of select="."/> 
        <!--</xsl:call-template>--> 
        <xsl:text>;</xsl:text> 
        <!--<xsl:variable name="temp" select="$check1"/>--> 
        </xsl:if> 
       </xsl:for-each> 
       <!--</xsl:if>--> 
       <xsl:for-each select="$text2"> 
        <xsl:if test="[email protected] and [email protected] "> 
        <xsl:value-of select="."/> 
        <xsl:text>;</xsl:text> 
        </xsl:if> 
       </xsl:for-each> 
       </xsl:for-each>    
      </Reason_Listed> 
      </Entity> 
     </xsl:for-each>    
     </xsl:template> 

的投入將是:

<Description1List> 
    <Description1Name Description1Id="1" RecordType="Person">Politically Exposed Person (PEP)</Description1Name> 
    <Description1Name Description1Id="2" RecordType="Person">Relative or Close Associate (RCA)</Description1Name> 
</Description1List> 
<Description2List> 
    <Description2Name Description2Id="1" Description1Id="1">Sanctions Lists</Description2Name> 
    <Description2Name Description2Id="2" Description1Id="2">Other Official Lists</Description2Name> 
    </Description2List> 
<Records> 
    <Person id="196542" action="add" date="19-Jul-2017"> 
     <Gender>Male</Gender> 
     <ActiveStatus>Active</ActiveStatus> 
     <Deceased>No</Deceased> 
     <NameDetails> 
     <Name NameType="Primary Name"> 
      <NameValue> 
      <FirstName>Nourirtg</FirstName> 
      </NameValue> 
     </Name> 
     </NameDetails> 
    <Descriptions> 
     <Description Description1="1" /> 
     <Description Description1="1" Description2="1" /> 
    </Descriptions> 
    </Person> 
<Records> 

謝謝:-)提前。

+0

@Rupesh你能幫我解決這個問題嗎? –

+0

你能分享預期的產出結構嗎? –

+0

我的輸出是:政治暴露人(PEP);政治暴露人(PEP);制裁列表 預期輸出:政治暴露人(PEP);制裁列表 @ AniketV –

回答

0
?xml version="1.0" encoding="utf-8"?> 
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl" 
> 
<xsl:key name="Desc" match="PFA/Records/Person/Descriptions/Description[@Description1]" use="@Description1"/> 
    <xsl:template match="/"> 
     <xsl:param name="text1" select="PFA/Description1List/Description1Name"/> 
     <xsl:param name="text2" select="PFA/Description2List/Description2Name"/> 
     <Entity_List Type="LIST_TYPE_CUSTOM_ENTITY" xmlns="https://support.bridgerinsight.lexisnexis.com/downloads/xsd/4.2/CWLEntityExport.xsd"> 
     <xsl:for-each select="PFA/Records/Person"> 
      <Entity> 
      <First_Name> 
       <xsl:value-of select="NameDetails/Name/NameValue/FirstName"/> 
      </First_Name> 
      <Reason_Listed> 
<xsl:if test="generate-id()=generate-id(key('Desc', @Description1)[1])"> 
       <xsl:for-each select="Descriptions/Description" > 
       <xsl:variable name="check1" select="@Description1"></xsl:variable> 
       <xsl:variable name="check2" select="@Description2"></xsl:variable> 
       <!--<xsl:if test="index-of(temp, $check1)!=()">--> 
       <xsl:for-each select="$text1"> 
        <xsl:if test="[email protected]"> 
        <xsl:value-of select="."/> 
        <!--</xsl:call-template>--> 
        <xsl:text>;</xsl:text> 
        <!--<xsl:variable name="temp" select="$check1"/>--> 
        </xsl:if> 
       </xsl:for-each> 
       </xsl:if> 
       <xsl:for-each select="$text2"> 
        <xsl:if test="[email protected] and [email protected] "> 
        <xsl:value-of select="."/> 
        <xsl:text>;</xsl:text> 
        </xsl:if> 
       </xsl:for-each> 
       </xsl:for-each>    
      </Reason_Listed> 
      </Entity> 
     </xsl:for-each>    
     </xsl:template> 
+0

我得到了使用鍵的結果。但有沒有辦法在每個循環之後重置? –

0

試試這個

<Reason_Listed> 
     <xsl:for-each select="Descriptions/Description"> 
      <xsl:variable name="check1" select="@Description1"/> 
      <xsl:variable name="check2" select="@Description2"/> 
      <xsl:choose> 
       <xsl:when test="@Description2"> 
        <xsl:value-of 
         select="$text2[@Description2Id = $check2 and @Description1Id = $check1]" 
        /> 
       </xsl:when> 
       <xsl:otherwise> 
        <xsl:value-of select="$text1[@Description1Id = $check1]"/> 
       </xsl:otherwise> 
      </xsl:choose> 
      <xsl:if test="position() != last()"> 
       <xsl:text>;</xsl:text> 
      </xsl:if> 
     </xsl:for-each> 
    </Reason_Listed> 

只要編輯您的第一個代碼。