2013-05-06 2 views
0

부모 위치에 따라 노드를 계산하려고합니다. XSL - 부모 위치에 따라 노드를 계산합니다.

은 예이다 : 각각 entry 들어

<tbody> 
    <row> 
     <entry>L1C1</entry> 
     <entry>L1C2</entry> 
     <entry>L1C3</entry> 
    </row> 
    <row> 
     <entry>L2C1</entry> 
     <entry morerows="1">L2C2</entry> 
     <entry>L2C3</entry> 
    </row> 
    <row> 
     <entry>L3C1</entry> 
     <entry>L3C3</entry> 
    </row> 
</tbody> 

, I는 그 속성 morerows는 행의 위치에 의존하는 수보다 row 요소 앞의 entry 소자의 수를 카운트 할.

나는 이런 일이 :

<xsl:variable name="nbRows"> 
    <xsl:value-of select="count(ancestor::tbody/row)"> 
    </xsl:value-of> 
</xsl:variable> 

<xsl:value-of select="count(parent::row/preceding-sibling::row/entry[@morerows &gt; ($nbRows - count(current()/../preceding-sibling::row))])"> 
</xsl:variable>"/> 

을하지만, 당신이 상상할 수있는,이 작동하지 않습니다.

누군가가 도와 줄 수 있습니까?

+0

영어로 쓸 수 있습니다 제발 무엇을 변환을 원하니? – Borodin

+0

속성 morerows가 (행 수 - 행 위치 + 1)보다 큰 이전 행 요소의 입력 요소 수를 알고 싶습니다. 이 번호에 따라 다른 수행 정보를 수행할지 여부를 결정합니다. 이 경우 빈으로 을 html로 추가합니다. – Johann

+0

예제를 통해 각 행의 결과 숫자는 무엇입니까? – JLRishe

답변

2

내가 제대로 질문을 이해하면이 작업을 수행해야합니다

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 

    <xsl:output method="xml" indent="yes"/> 

    <xsl:template match="row"> 
    <xsl:variable name="nRows" select="count(../row)"/> 
    <xsl:variable name="precedingEntries" select="preceding-sibling::row/entry"/> 
    <xsl:variable name="minMoreRows" select="$nRows - position() + 1"/> 
    <n> 
     <xsl:value-of select="count($precedingEntries[@morerows>=$minMoreRows])"/> 
    </n> 
    </xsl:template> 

    <xsl:template match="/"> 
    <root> 
     <xsl:apply-templates/> 
    </root> 
    </xsl:template> 

</xsl:stylesheet> 

출력 - 질문의 예에 적용 -이다 :

<root> 
    <n>0</n> 
    <n>0</n> 
    <n>1</n> 
</root> 
+0

사실,이 제안은 내 문제를 해결하지 못합니다. 네 번째 행 요소를 3 개의 무작위 항목 요소로 예제에 추가하면 0 0 1 0을 얻을 것으로 예상되지만 제안에 따라 0 0 1 1이됩니다. $ minMoreRows 변수를 계산할 때 사용하는 "position()" 현재 행의 위치가 아닌 "잠재적"항목 요소의 위치 여야합니다. 나는 계산에서 실수를 했으므로 새로운 예를 들어 보겠습니다. 3 행에 있다고 상상하면, morerows 속성이 3 - 1 = 2보다 큰 첫 번째 행의 항목 요소를 계산하려고합니다. – Johann

+0

morerows 속성이 3 - 2 = 1보다 크거나 같은 두 번째 행의 입력 요소도 계산합니다. – Johann

+0

두 카운트는 최종 결과를 예상합니다. – Johann

관련 문제