2014-05-21 3 views
0

다음 xml 파일이 있습니다.속성 값을 기반으로 xsl : key에 의해 반환 된 가방에서 중복 제거

<Bank> 
    <Person personId="1" type="1071" deleted="0"> 
    </Person> 
    <Person personId="2" type="1071" deleted="0"> 
    </Person> 
    <Person personId="3" type="1071" deleted="0"> 
    </Person> 
    <Account> 
    <Role personId="1" type="1025" /> 
    </Account> 
    <Account> 
    <Role personId="1" type="1025" /> 
    </Account> 
    <Account> 
    <Role personId="1" type="1018" /> 
    </Account> 
    <Account> 
    <Role personId="3" type="1025" /> 
    <Role personId="1" type="1018" /> 
    </Account> 
    <Account> 
    <Role personId="2" type="1025" /> 
    </Account> 
</Bank> 

다음 XSL 변환.

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    <xsl:output method="text" encoding="ISO-8859-1" /> 
    <xsl:strip-space elements="*" /> 

    <xsl:key name="roleKey" 
    match="Role[(@type = '1025' or @type = '1018' or @type = '1022' or @type = '1023') and not(@validTo)]" 
    use="@personId" /> 

    <xsl:template match="Person"> 
    <xsl:value-of select="@personId" /> 
    <xsl:variable name="roles" select="key('roleKey', @personId)" /> 
    <xsl:for-each select="$roles"> 
     <xsl:text>;</xsl:text><xsl:value-of select="@type" /> 
    </xsl:for-each> 
    <xsl:text>&#xA;</xsl:text> 
    </xsl:template> 
</xsl:stylesheet> 

실제 결과는 다음과 내가 중복 type 값을 제거하고 싶습니다. 내가 this website에서 키워드 following 또한 Muenchian 방법으로 트릭을 포함하는 팁을 시도

1;1025;1018 
2;1025 
3;1025 

1;1025;1025;1018;1018 
2;1025 
3;1025 

다음과 같이 예상되는 결과는해야한다 .... 그들은 personId 속성으로 정의 된 Person 컨텍스트에서만 중복을 제거하려는 반면에 전체 문서를 탐색하고 Person 요소 각각에 대해 중복을 매치하는 것처럼 보이는 것처럼 작동하지 않습니다.

key에 의해 반환 된 가방에서 중복 된 것을 어떻게 제거합니까? 아니면 내가 원하는 것을 인쇄하기 위해 xsl:for-each에서 사용할 수있는 방법이 있을까요?

XSLT 1.0에서 사용할 수있는 것만 사용할 수 있습니다. XSLT 2.0 프로세서를 사용할 수있는 가능성은 없습니다.

답변

1

이 솔루션이 사용 가능한지는 알 수 없지만 이러한 키를 도입하고 Muenchian 메서드를 사용하여 원하는 바를 달성했습니다. 전체 변화는 변화 후의 그 모양

<xsl:key name="typeKey" match="Role" use="concat(@type, '|', @personId)" /> 

...

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    <xsl:output method="text" encoding="ISO-8859-1" /> 
    <xsl:strip-space elements="*" /> 

    <xsl:key name="roleKey" 
    match="Role[(@type = '1025' or @type = '1018' or @type = '1022' or @type = '1023') and not(@validTo)]" 
    use="@personId" /> 
    <xsl:key name="typeKey" match="Role" use="concat(@type, '|', @personId)" /> 

    <xsl:template match="Person"> 
    <xsl:value-of select="@personId" /> 
    <xsl:variable name="roles" select="key('roleKey', @personId)" /> 
    <xsl:for-each select="$roles[generate-id() = generate-id(key('typeKey', concat(@type, '|', @personId)))]"> 
     <xsl:text>;</xsl:text><xsl:value-of select="@type" /> 
    </xsl:for-each> 
    <xsl:text>&#xA;</xsl:text> 
    </xsl:template> 
</xsl:stylesheet> 

와 실제 결과가 이제 ...

1;1025;1018 
2;1025 
3;1025