>I agree that is the way to go if there are no recursive references.
But if there are recursive references then that approach causes the
program goes into an infinite loop. My XML document has lots of complex,
indirect recursive references.
I don't quite see how the use of variables will prevent the infinite
recursion.
To prevent infinite recursion you need to detect cycles, and the way to
do that is to pass on each template call a list of the idref's currently
being expanded, and check an idref against that list before you expand it
<xsl:template match="*[@idref]">
<xsl:param name="active" as="xs:string*"/>
<xsl:copy>
<xsl:copy-of select="@* except @idref" />
<xsl:variable name="refed-element" select="key('ids', @idref)"/>
<xsl:if test="exists($refed-element) and not(@idref = $active)">
<xsl:apply-templates select="key('ids', @idref)">
<xsl:with-param name="active" select="($active, @idref)"/>
</xsl:apply-templates>
</xsl:if>
</xsl:copy>
</xsl:template>
Michael Kay
Saxonica
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--