Subject: Re: [xsl] generate-id for identical elements From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx> Date: Thu, 23 Sep 2004 20:19:49 +0100 |
To summarize the problem, I have identical elements (but they do have different parent elements), and I am trying to get cross-references to these identical elements with generate-id().
<xsl:template match="chapter"> <h1><a name="{generate-id()}"/><xsl:value-of select="@title"/></h1> <xsl:apply-templates/> </xsl:template>
<xsl:template match="ref"> <xsl:variable name="reftext"> <xsl:call-template name="makeRef"> <xsl:with-param name="inString" select="@target"/> </xsl:call-template> </xsl:variable> <a href="#{generate-id(//$reftext)}"><xsl:value-of select="."/></a> </xsl:template>
<xsl:function name="my:parsePath" as="element()"> <xsl:param name="path" as="xs:string" /> <xsl:sequence select="my:parsePath($path, $book)" /> </xsl:function>
<xsl:function name="my:parsePath" as="element()"> <xsl:param name="path" as="xs:string" /> <xsl:param name="element" as="element()" /> <xsl:variable name="step" as="xs:string" select="if (contains($path, '/')) then substring-before($path, '/') else $path" />
<xsl:variable name="elementName" as="xs:string" select="substring-before($step, '|')" /> <xsl:variable name="title" as="xs:string" select="substring-after($step, '|')" />
<xsl:variable name="newElement" as="element()" select="$element/*[name() = $elementName][@title = $title]" />
<xsl:sequence select="if (contains($path, '/')) then my:parsePath(substring-after($path, '/'), $newElement) else $newElement" /> </xsl:function>
<xsl:template match="ref"> <xsl:variable name="reftext" select="my:parsePath(@target)" /> <a href="#{generate-id($reftext)}"><xsl:value-of select="."/></a> </xsl:template>
<xsl:template name="my:parsePath"> <xsl:param name="path" /> <xsl:param name="element" select="/book" /> <xsl:variable name="step"> <xsl:choose> <xsl:when test="contains($path, '/')"> <xsl:value-of select="substring-before($path, '/')" /> </xsl:when> <xsl:otherwise> <xsl:value-of select="$path" /> </xsl:otherwise> </xsl:choose> </xsl:variable>
<xsl:variable name="elementName" select="substring-before($step, '|')" /> <xsl:variable name="title" select="substring-after($step, '|')" />
<xsl:variable name="newElement" select="$element/*[name() = $elementName][@title = $title]" />
<xsl:choose> <xsl:when test="contains($path, '/')"> <xsl:call-template name="my:parsePath"> <xsl:with-param name="path" select="substring-after($path, '/')" /> <xsl:with-param name="element" select="$newElement" /> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:value-of select="generate-id($newElement)" /> </xsl:otherwise> </xsl:choose> </xsl:template>
<xsl:template match="ref"> <xsl:variable name="reftext"> <xsl:call-template name="my:parsePath"> <xsl:with-param name="path" select="@target" /> </xsl:call-template> </xsl:variable> <a href="#{$reftext}"><xsl:value-of select="."/></a> </xsl:template>
Jeni -- Jeni Tennison http://www.jenitennison.com
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] generate-id for identical, JBryant | Thread | Re: [xsl] generate-id for identical, JBryant |
[xsl] Advantages of using key()?, yguaba | Date | Re: [xsl] Specify/determine element, Jeni Tennison |
Month |