xsl-list
[Top] [All Lists]

Re: question on preceding nodes

2003-03-31 17:12:53
Hi John,

The XPath Location Path in the test

<xsl:when test="preceding::/*/*/C[(_at_)name=current()/@name]">

isn't correct. It shouldn't parse at all (you should get a compile-time error).

Try, simply,

preceding::C[(_at_)name=current()/@name]

Since any location path step must be constructed as

axisname::nodetest[optionalpredicate]

and yours has no node test, but rather '/*/*/C' which looks like a location path on its own (composed of three steps, child:: axis implicit in each step, node tests '*', '*' and 'C'). If this use of jargon suggests to you that studying the anatomy of XPath may be worth the time spent -- you're right.

And in general you need to clean up, as in something like

<xsl:template match="C">
  <xsl:value-of select="@name"/>
  <xsl:if test="preceding::C[(_at_)name=current()/@name]">
   <xsl:text>_</xsl:text>
    <xsl:value-of select="../@number"/>
  </xsl:if>
</xsl:template>

I hope that helps--

Cheers,
Wendell

At 06:07 PM 3/31/2003, you wrote:
<xsl:template match="C">
    <xsl:for-each select="C">
        <xsl:choose>
        <xsl:when test="preceding::/*/*/C[(_at_)name=current()/@name]">
            <xsl:value-of select="current()/@name"/>_<xsl:value-of
select="../BOX/@number"/>
        </xsl:when>
        <xsl:otherwise>
            <xsl:value-of select="current()/@name"/>
        </xsl:otherwise>
    </xsl:for-each>
</xsl:template>

but this never produces the "_2" in "pen_2".

Any tip?


======================================================================
Wendell Piez                            
mailto:wapiez(_at_)mulberrytech(_dot_)com
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
======================================================================


XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



<Prev in Thread] Current Thread [Next in Thread>