saxon XSLT 프로세서가 버그인지 기능인지 알 수없는 비정상적인 동작이 발생했습니다 : generate-id()가 동일한 노드에서 동일한 ID를 생성하지 않습니다 . (단순한 방법으로 같은 출력을 얻을 수는 있지만 효과는 보이지 않습니다.)generate-id가 동일한 노드에 다른 ID를 생성합니다.
입력 XML은 다음과 같이 간단합니다 :
<list>
<entry>beta</entry>
<entry>gamma</entry>
<entry>alpha</entry>
</list>
이 입력이 스타일을 "기본"ID를 d1
시작하면서 d2
와 mkIndex
시작에서 발생하는 모든 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>
와
명확하고 유용한 답변 - 감사합니다! – leu