[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] ancestor

Subject: Re: [xsl] ancestor
From: "M. David Peterson" <m.david@xxxxxxxxxx>
Date: Mon, 18 Oct 2004 10:23:47 -0700

Has this test returned a value for you?

<xsl:if test="$inlineequation/@id=./@id"><xsl:value-of
select="position()" /></xsl:if>

My guess is that you are trying to do this:

<xsl:if test=". = @id">
<xsl:value-of select="position()" />

Which really doesnt make much logical sense iso then maybe the value you are passing in to the parameter 'inlinequation' contains an attribute id and you want to compare its value to the value of the current elements id attribute which would look like this:

<xsl:if test="$inlineequation/@id = current()/@id">
<xsl:value-of select="position()" />

But from your explanation it seems you are simply trying to generate sequential numbering which can be done by simply using the number element as such:

<xsl:for-each select="//inlineequation[not(ancestor::table) and

Or better yet just eliminate the named template all together and use apply-templates and the match attribute of the template as it was before and put the number element inside the template like so:

<xsl:template match="inlineequation">
<xsl:value-of select="put desired output element here"/>

Not quite sure as to whether or not this helps or not as its unclear to me what it is you want to output and what type of ordering values need to be along side it. But hopefully this will get you going a little more in the right direction.

Best of luck!


Jiang, Peiyun wrote:
Thanks, everyone!

I picked up "inlineequation[not(ancestor::table)]" because it looks neat and
it works!!!
Testing for ancestor does not seem to slow down my application. The // part
probaly is the critical "PATH" as Jeni said. My "inlineequation" is all over
the document nesting with different depths and I'll use "//" for now.

The pain part is this (though my XSLT is not too slow as measured on my
computer): I'm trying to output the position of each selected inlineequation (using
inlineequation[not(ancestor::table)]). The numbering is sequential in the
selected inlineequations. What I'm doing is when each inlineequation is
matched, I call a template that will get the position in the selected list.
"inlineequation[not(ancestor::table)]" is evaluated over and over again.

  <xsl:template name="inlineequation_position">
     <xsl:param name="inlineequation"></xsl:param>
     <xsl:for-each select="//inlineequation[not(ancestor::table) and
        <xsl:if test="$inlineequation/@id=./@id"><xsl:value-of
select="position()" /></xsl:if>

simplified calling template:
<xsl:template match="inlineequation">
<img alt="">
<xsl:attribute name="src">ImgServer?<xsl:call-template
name="inlineequation" select="."/></xsl:call-template>h.gif</xsl:attribute>
</img> </xsl:template>

Is there a way to cache the result of
"//inlineequation[not(ancestor::table)]" in a variable and pass it to the
template? There seems to be two problems with this approach: a global
variable may not have access to the document and can we pass two parameters
to a template?


Peiyun Jiang

Current Thread