2013-11-28 3 views
0

안녕하세요 현재 노드가 다른 노드와 일치하는지 테스트하려고합니다. 내가 B800/B840/CTRY는 B400/B475/CTRY에 포함되어 있는지 여부를 확인할 수 있도록하고 싶습니다xslt 현재 노드를 다른 노드와 테스트/일치

<top-level> 
<ep-bulletin> 
    <SDOBI> 
     <B200> 
      <B210>R1</B210> 
     </B200> 
     <B400> 
      <B472> 
       <B475> 
        <date>20030221</date> 
        <ctry>GB</ctry> 
        <date>20030222</date> 
        <ctry>LU</ctry> 
       </B475> 
      </B472> 
     </B400> 
     <B800> 
      <B840> 
       <ctry>DE</ctry> 
       <ctry>FR</ctry> 
       <ctry>GB</ctry> 
       <ctry>IT</ctry> 
       <ctry>LU</ctry> 
       <ctry>SE</ctry> 
      </B840> 
     </B800> 
    </SDOBI> 
</ep-bulletin> 
<ep-bulletin> 
    <SDOBI> 
     <B200> 
      <B210>R2</B210> 
     </B200> 
     <B400> 
      <B472> 
       <B475> 
        <date>20040609</date> 
        <ctry>AT</ctry> 
        <date>20110630</date> 
        <ctry>BE</ctry> 
        <date>20110630</date> 
        <ctry>CH</ctry> 
        <date>20120103</date> 
        <ctry>DE</ctry> 
        <date>20110630</date> 
        <ctry>DK</ctry> 
        <date>20110630</date> 
        <ctry>FR</ctry> 
        <date>20110612</date> 
        <ctry>GB</ctry> 
        <date>20110612</date> 
        <ctry>IT</ctry> 
        <date>20110630</date> 
        <ctry>LI</ctry> 
        <date>20120101</date> 
        <ctry>NL</ctry> 
        <date>20110613</date> 
        <ctry>SE</ctry> 
       </B475> 
      </B472> 
     </B400> 
     <B800> 
      <B840>       

       <ctry>AT</ctry> 
       <ctry>BE</ctry> 
       <ctry>CH</ctry> 
       <ctry>DE</ctry> 
       <ctry>DK</ctry> 
       <ctry>ES</ctry> 
       <ctry>FR</ctry> 
       <ctry>GB</ctry> 
       <ctry>IT</ctry> 
       <ctry>LI</ctry> 
       <ctry>NL</ctry> 
       <ctry>SE</ctry> 
      </B840> 
     </B800> 
    </SDOBI> 
</ep-bulletin> 
</top-level> 

: 이것은 내 XML이다. 얻을 수있는 출력은 첫 번째 열에 레코드 ID가 들어있는 테이블입니다. 두 번째 열에는 현재 노드가 있고 세 번째 노드에는 일치 노드 앞에있는 노드 B475/date (| ~ |는 텍스트 식별자입니다. 분리기).

|~|R1|~|;|~|DE|~|;|~||~| 
|~|R1|~|;|~|FR|~|;|~||~| 
|~|R1|~|;|~|GB|~|;|~|20030221|~| 
|~|R1|~|;|~|IT|~|;|~||~| 
|~|R1|~|;|~|LU|~|;|~|20030222|~| 
|~|R1|~|;|~|SE|~|;|~||~| 
|~|R2|~|;|~|AT|~|;|~|20040609|~| 
|~|R2|~|;|~|BE|~|;|~|20110630|~| 
|~|R2|~|;|~|CH|~|;|~|20110630|~| 
|~|R2|~|;|~|DE|~|;|~|20120103|~| 
|~|R2|~|;|~|DK|~|;|~|20110630|~| 
|~|R2|~|;|~|ES|~|;|~||~| 
|~|R2|~|;|~|FR|~|;|~|20110630|~| 
|~|R2|~|;|~|GB|~|;|~|20110612|~| 
|~|R2|~|;|~|IT|~|;|~|20110612|~| 
|~|R2|~|;|~|LI|~|;|~|20110630|~| 
|~|R2|~|;|~|NL|~|;|~|20120101|~| 
|~|R2|~|;|~|SE|~|;|~|20110613|~| 

이것은 내가 작성한 xslt 코드이지만 마지막 열을 가져올 수 없습니다.

<?xml version="1.0" encoding="utf-8"?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
<xsl:output method="text" version="1.0" encoding="UTF-8" indent="no"/> 
<xsl:template match="/"> 

<xsl:text>&#13;&#10;</xsl:text> 

<xsl:for-each select="top-level/ep-bulletin/SDOBI/B800/B840/ctry"> 

<xsl:text>|~|</xsl:text> 

<xsl:value-of select="../../../B200/B210"/> 

<xsl:text>|~|;|~|</xsl:text> 

<xsl:value-of select="."/> 

<xsl:text>|~|;|~|</xsl:text> 

<xsl:choose> 
<xsl:when test=".=child::B475"> 
<xsl:value-of select="../../../preceding::B475/ctry"/> 
</xsl:when> 
<xsl:otherwise > 
<xsl:value-of select=""> 
</xsl:otherwise> 
</xsl:choose> 

<xsl:text>|~|</xsl:text> 
<xsl:text>&#13;&#10;</xsl:text> 

</xsl:for-each> 
</xsl:template> 
</xsl:stylesheet> 

도움을 주셔서 감사합니다.

답변

0

난 당신이 .=child::B475 달성해야 어떻게 생각하는지 모르겠지만,이 경우 단지

<xsl:value-of select="../../../B400/B472/B475 
         /ctry[. = current()]/preceding-sibling::date[1]" /> 

<xsl:choose> 
<xsl:when test=".=child::B475"> 
<xsl:value-of select="../../../preceding::B475/ctry"/> 
</xsl:when> 
<xsl:otherwise > 
<xsl:value-of select=""> 
</xsl:otherwise> 
</xsl:choose> 

전체를 교체, 당신이 일을 공정한 조금을 단순화 할 수 있다고 생각 ctry 아래의 B475은 현재 하나와 일치합니다. 그러면 바로 앞에 date이 인쇄됩니다 (두 가지 이상이 일치하는 경우 ctry이 나오면 t 그는 앞에 date가 먼저과 일치합니다. 그러한 ctry이 없으면 아무 것도 인쇄하지 않습니다. select 표현식이 노드를 찾지 못하면 value-of이 빈 문자열을 자동으로 제공하기 때문에 choose이 필요하지 않습니다. value-of 빈 노드 세트가 빈 문자열로 정의됩니다.

+0

많은 감사이 이안! 그것은 완벽하게 작동합니다! – user2406147

관련 문제