2017-02-15 3 views
0

xslt에 대해 unparsed-text()를 수행하고 있습니다.일치하는 하위 문자열의 XSLT 그룹화

 <xsl:template match="/" name="text2xml"> 
     <xsl:variable name="entries" as="node()*"> 
     <xsl:analyze-string select="$textfile" regex="\r\n?|\n"> 
      <xsl:non-matching-substring> 
       <xsl:analyze-string select="." regex="someregcode"> 
     <xsl:matching-substring> 
      <group> 
      <thistagwithsomeattributes> 
      <abc>some value coming from regex</abc> 
      <cde>some value from regex</cde> 
      </thistagwithsomeattributes> 
      </group> 
     </xsl:matching-substring> 
     </xsl:analyze-string> 
      </xsl:non-matching-substring> 
      </xsl:analyze-string>  
    </xsl:variable> 

<xsl:for-each-group select="$entries" group-by="abc"> 
     <final> 
     <xsl:copy-of 
      select="current-group()[1]/abc,current-group()/*[not(self::abc)]"/> 

     </final> 
     </xsl:for-each-group>  

을 위의 나를 위해 작동하지 않습니다 그래서 데이터는 다음과 같이

내가 matching-string에서 그룹의 일부로서 요소 thistagwithsomeattributes의 닫는 태그를 얻을 필요가 텍스트 파일에서오고있다 . 요소 thistagwithsomeattributes을 제거하면 작동합니다. 이 요소를 일치하는 하위 문자열의 그룹에 포함시키는 방법 이 요소의 속성이 그룹에 대해 다른 값을 갖고 있기 때문에 나는이 필요

내가 (다음 XML 구조) 달성하기 위해 노력하고있어 :

<thistagwithsomeattributes att1="fromregexwithinggroup" att2="fromregexwithinggrouop"> 
<someelement> 
<anothertagwithattributes att1="fromregexvalues"> 
<cont> 
    <itm> 
     abc>some value coming from regex</abc> 
    <cde>some value from regex</cde> 
    </itm> 
</cont> 
</anothertagwithattributes> 
</thistagwithsomeattributes> 

를 이제 입력 할 때 <thistagwithsomeattributes><anothertagwithattributes>, 작동하지 않음 (결과 없음), xml 파일이 비어 있습니다. 하지만 내가 그들을 제거 할 때. 다음 결과를 얻었습니다.

+1

"작동하지 않는다"고 말할 때 정확한 오류 메시지와 함께 문제를 재현 할 수 있도록 XML과 XSLT의 최소한이지만 완전한 예제를 게시하십시오. –

+0

@Martin Honnen : 더 많은 샘플과 내가 성취하려고하는 것을 편집했습니다. 이전에 게시하지 않은 것에 대해 사과드립니다. – user726720

답변

1

<xsl:for-each-group select="$entries"<xsl:for-each-group select="$entries/thistagwithsomeattributes"으로 조정해야합니다.

+0

간단한 예제를 제공 할 수 있습니까? – user726720

+0

변수 구조에서 올바른 요소를 선택하려면 표시된대로 'select'표현식을 적용해야합니다. –

+0

이''와 같이'select'에 적응했습니다. 결과를 표시하지만 'thistagwithsomeattributes'는 결과에 포함되지 않습니다. – user726720