2014-07-14 3 views
0

이 XML을 받았고 대부분 렌더링해야하지만 대부분 잘 작동하지만 키가 일치하는 color의 노드 집합을 추출하려고 애쓰는 중이다. bar 요소의 key이고 속성은 하드 코딩 된 문자열 (이 경우 'data')입니다. 노드 - 세트는 템플릿에 매개 변수로 전달되어야하며, 각 컬러 라인은 한 번만 표시합니다XSLT 1.0 - 노드 집합을 추출하고 매개 변수로 전달

<report> 
    <settings> 
     <colors> 
      <color key="1-1" name="frame" value="..." ... /> 
      <color key="1-1" name="data" value="..." ... /> 
      <color key="2-1" name="frame" value="..." ... /> 
      <color key="2-1" name="data" value="..." ... /> 
      <color key="3-1" name="frame" value="..." ... /> 
      <color key="3-1" name="data" value="..." ... /> 
     </colors> 
     <comp> 
      <cont> 
        <bar key="1-1" .../> 
        <bar key="1-1" .../> 
        <bar key="2-1" .../> 
      </cont> 
     <comp> 
     <!-- possibly more <comp/cont/bar> below that may not be mixed with the above --> 
    </settings> 
</report> 

을 내 XSLT 파일에서 나는이 (추출물)가 :

<xsl:key name="barnode" match="bar" use="@key"/> 
<xsl:key name="colorlookup" match="/report/settings/colors/color" use="@key"/> 

<!-- this runs at the `cont` element level, i.e. `bar` can be accessed without prefix --> 

<!-- set $x to the node-list of bars with unique @key attribute --> 
<xsl:call-template name="renderit"> 
    <xsl:with-param name="colors"> 
     <!-- 'bars' contains node-set of 'bar' elements with @key being unique --> 
     <xsl:variable name="bars" select="bar[generate-id() = generate-id(key('barnode', @key)[1])]"/> 
     <xsl:for-each select="$bars"> 
      <xsl:value-of select="key('colorlookup', @key)[@name='data']"/> 
     </xsl:for-each> 
    </xsl:with-param> 
</xsl:call-template> 

문제는 이것은 노드 집합을 전달하지 않고 트리 조각을 전달한다는 것입니다. 위와 같지만 node-set을 반환하는 선택을 할 수 있습니까?

편집 :

예상 노드 집합 :

<color key="1-1" name="data" value="..." ... /> 
<color key="2-1" name="data" value="..." ... /> 

내가 디버그 (을 인쇄하는 방법을 알고하지 않는 제시된 XSLT도이 결과 트리 조각을 생성하는 경우 확실하지 않다 목적).

+0

이 예상 된 결과를 게시하시기 바랍니다보십시오. 또한 XSLT 1.0 또는 2.0을 사용하는지 나타냅니다. –

답변

2

<xsl:with-param name="colors" select="key('colorlookup', bar[generate-id() = generate-id(key('barnode', @key)[1])]/@key)[@name = 'data']"/> 
+0

지금은 단순 해 보이지만 감사합니다! :) – galmok