You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xalan.apache.org by Douglas Conklin <do...@nightfire.com> on 2002/02/20 03:40:45 UTC

RE: problem with the position function -- addendum

The problem doesn't seem to be in the position function(), some
rearrangement of the XSL shows the index param is not being given the value
of the position() function. 

	easy,
	douglas d


-----Original Message-----
From: Douglas Conklin 
Sent: Tuesday, February 19, 2002 6:36 PM
To: 'xalan-j-users@xml.apache.org'
Subject: problem with the position function


Hi all,

    I am having a problem with the position() function when processing with
Xalan-J 2.2.0.

    In one particular usage of position() against a series of nodes, the
position() function always returns 0. 
    when processing with Xalan-J 1.0.1 the same application of the position
function returns the appropriate number. 

    I looked in the Xalan-j 2.2.0 docs / release notes / bug list, as well
as searched this mailing list, and I haven't seen anything like this. 

    Is this a tightening of processor against the XSL spec, or is this a bug
in the processor?

    TIA.

	easy,
	douglas d



    Here are a small example stylesheet, input xml, Xalan 1.0.1 output, and
Xalan 2.2.0 output.

    Note that when I remove the -1 from <xsl:value-of
select="position()-1"/> so that it is <xsl:value-of select="position()"/>,
the numbers are all 0, so it isn't the addition that is failing. 

_________________________________
xsl
_________________________________

<?xml version="1.0"?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">

<xsl:template match="/">
	<Request>
		<xsl:apply-templates/>
	</Request>
</xsl:template>

<xsl:template match="directorycontainer">
	<directorycontainer type="container">
		<directory>
			<xsl:apply-templates select="directory"/>
		</directory>
	</directorycontainer>
</xsl:template>

<xsl:template match="directory">
	<xsl:apply-templates>
		<xsl:with-param name="index">
			<xsl:value-of select="position()-1"/>
		</xsl:with-param>
	</xsl:apply-templates>
</xsl:template>

<xsl:template match="directory/*">
	<xsl:param name="index"/>
	<xsl:variable name="field">
		<xsl:value-of select="name()"/>
	</xsl:variable>
	<xsl:variable name="field_index">
		<xsl:value-of select="concat($field,'_',$index)"/>
	</xsl:variable>
	<xsl:element name="{$field_index}">
		<xsl:attribute name="value">
			<xsl:value-of select="@value"/>
		</xsl:attribute>
	</xsl:element>
</xsl:template>

</xsl:transform>

_________________________________
input xml
_________________________________

<Request>
	<directorycontainer type="container">
		<directory>
			<A value="a"/>
		</directory>
		<directory>
			<B value="b"/>
		</directory>
		<directory>
			<C value="c"/>
		</directory>
	</directorycontainer>
</Request>


_________________________________
Xalan 1.0.1 output XML 
(what I was getting and would like to get)
_________________________________

<?xml version="1.0" encoding="UTF-8"?>
<Request>
	<directorycontainer type="container">
		<directory>
			<A_0 value="a"/>
		
			<B_1 value="b"/>
		
			<C_2 value="c"/>
		</directory>
	</directorycontainer>
</Request>



_________________________________
Xalan 2.2.0 output XML 
(what I get now which I don't like)
_________________________________

<?xml version="1.0" encoding="UTF-8"?>
<Request>
	<directorycontainer type="container"><directory>
			<A_-1 value="a"/>
		
			<B_-1 value="b"/>
		
			<C_-1 value="c"/>
		</directory></directorycontainer>
</Request>