[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: ancestor

Subject: RE: ancestor
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Mon, 18 Oct 2004 14:51:02 -0400
xsl ancestor
Peiyun,

At 02:40 PM 10/18/2004, you wrote:
>Has this test returned a value for you?
><xsl:if test="$inlineequation/@id=./@id"><xsl:value-of
>select="position()" /></xsl:if>
Yes, I got the one I needed.

>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()" />
></xsl:if>
Yes, you are right.

More generally, I'm trying to get the position of an element in a selected
list of elements. All elements are identifiable by   @id. If the element is
not selected (even if it matches the element name) in the list, then nothing
is output. I need the position of that element a few times in a matching
template for that element in different places.

If you can describe exactly the elements whose positions you want in a match pattern, I think the easiest way to get what you want is probably to use xsl:number:


<xsl:template match="inlineequation" mode="number">
  <xsl:number count="inlineequation[not(ancestor::table)]" level="any"/>
  <!-- any formatting you want always to appear with your number, can
       go in this template too -->
<xsl:template>

<xsl:template match="inlineequation[not(ancestor::table)]">
  <xsl:apply-templates select="." mode="number"/>
  ... do your other stuff ...
</xsl:template>

This is much simpler than the approach you are currently trying. It might or might not perform better, depending on the processor (xsl:number can sometimes be slow). Other contingencies will affect this: for example, if I were outputting all the equations together, the gathering and counting by position would be more attractive. If, however, I had to reach in and find the correct node to number from my bunch, I'd try this method first.

Note also that if you can't use a pattern to distinguish just the nodes you want, you have to use the more complex approach. (We saw that a couple of days ago with numbering tables and figures in order of first reference to them....)

Cheers,
Wendell


====================================================================== Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx Mulberry Technologies, Inc. http://www.mulberrytech.com 17 West Jefferson Street Direct Phone: 301/315-9635 Suite 207 Phone: 301/315-9631 Rockville, MD 20850 Fax: 301/315-8285 ---------------------------------------------------------------------- Mulberry Technologies: A Consultancy Specializing in SGML and XML ======================================================================

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.