2013-09-02 2 views
0

saxon XSLT 프로세서가 버그인지 기능인지 알 수없는 비정상적인 동작이 발생했습니다 : generate-id()가 동일한 노드에서 동일한 ID를 생성하지 않습니다 . (단순한 방법으로 같은 출력을 얻을 수는 있지만 효과는 보이지 않습니다.)generate-id가 동일한 노드에 다른 ID를 생성합니다.

입력 XML은 다음과 같이 간단합니다 :

<list> 
<entry>beta</entry> 
<entry>gamma</entry> 
<entry>alpha</entry> 
</list> 

이 입력이 스타일을 "기본"ID를 d1 시작하면서 d2mkIndex 시작에서 발생하는 모든 ID를 사용

<?xml version="1.0" encoding="utf-8"?> 
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> 
    <xsl:template match="/"> 
    <output> 
     <xsl:apply-templates/> 

     <xsl:call-template name="mkIndex"> 
     <xsl:with-param name="rootParam" select="." /> 
     </xsl:call-template> 
    </output> 
    </xsl:template> 

    <xsl:template match="entry"> 
    <a id="{generate-id(.)}"> 
     <xsl:apply-templates/> 
    </a> 
    </xsl:template> 

    <xsl:template name="mkIndex"> 
    <xsl:param name="rootParam"/> 
    <xsl:variable name="rootVar"> 
     <xsl:copy-of select="."/> 
    </xsl:variable> 

    <!-- use $rootParam here to get the correct IDs with generate-id()--> 
    <xsl:for-each select="$rootVar//entry"> 
     <xsl:sort select="."/> 
     <a href="#{generate-id(.)}"> 
     <xsl:copy-of select="text()"/> 
     </a> 
    </xsl:for-each> 
    </xsl:template> 
</xsl:transform> 

로 변환된다.

대신 변수 $rootParam을 사용하는 경우 mkIndex에서 생성 된 ID는 기본 ID와 동일하게 보입니다. 텍스트는 두 경우 모두 동일하므로 두 경우 모두 동일한 노드를 처리합니다.

왜 동일한 노드가 generate-id()로 다른 ID를 얻는 지 이해할 수 없습니다. 어쩌면 누군가가 그 차이를 설명 할 수 있습니다.

코드

<xsl:variable name="rootVar"> 
    <xsl:copy-of select="."/> 
</xsl:variable> 

답변

3

레우 감사합니다, 당신은 입력 나무에 사람의 전체 복사본을하지만하지 않은 새로운 노드 (와 임시 트리를 생성 그들과 동일). 당신이 입력 트리의 노드 작업 할 경우

그래서

<xsl:variable name="rootVar" select="."/> 

에 해당 코드를 변경합니다.

+0

명확하고 유용한 답변 - 감사합니다! – leu

관련 문제