[xsl] Re: RE: accessing node[$position]

Subject: [xsl] Re: RE: accessing node[$position]
From: Dimitre Novatchev <dnovatchev@xxxxxxxxx>
Date: Wed, 5 Jun 2002 07:35:37 -0700 (PDT)
"Michael Kay" <michael dot h dot kay at ntlworld dot com> wrote:

> > In trying to reorder a set of nodes, I've run into a
> > problem with doing this:
> > 
> > <xsl:variable name="this_page" 
> > select="descendant::page[$the_position]"/>
> > or
> > <xsl:value-of
> > select="descendant::page[$the_position]"/>
> > 
> > ($the_position is a parameter that's passed in.)
> > Xselerator seems to have a problem with anything
> > involving something like node[$param_or_variable],
> > saying that the variable cannot be resolved
> 
> Either there's a bug in Xselerator, or there's a mistake in a part of
> your stylesheet that you haven't shown us. You can find out which is 
> the case by either (a) running your stylesheet through another XSLT
> processor, or (b) posting it on this list.

I think there's a slight misunderstanding here. What the original
message attempted to say is that node[$param_or_variable] didn't
produce the expected result when the $param_or_variable was set 
***externally***.

XSelerator is not an XSLT processor -- it only uses existing XSLT
processors to perform a transformation.

When a parameter is specified and set externally, usually the value is
interpreted as a string and the user cannot specify a more concrete
datatype for a parameter on the command line.

For example, invoking Saxon 6.5 from the command line like this:

F:\XML\MyTests\TestSaxon>java  com.icl.saxon.StyleSheet   numList.xml
testParams.xsl x="5"

with the following files:

numList.xml:
-----------
<nums>
  <num>01</num>
  <num>02</num>
  <num>03</num>
  <num>04</num>
  <num>05</num>
  <num>06</num>
  <num>07</num>
  <num>08</num>
  <num>09</num>
  <num>10</num>
</nums>


testParams.xsl:
--------------
<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
  
  <xsl:param name="x"/>
  
  <xsl:template match="/">
    <xsl:value-of select="/*/*[$x]"/>
  </xsl:template>
</xsl:stylesheet>

produces the following output:

<?xml version="1.0" encoding="utf-8"?>01


Therefore, the problem is not with XSelerator.

A good way to overcome this problem is to specify to the XSLT
processor, that the type is numeric. In case in the above stylesheet we
change:

    <xsl:value-of select="/*/*[$x]"/>
to
    <xsl:value-of select="/*/*[number($x)]"/>

Then the result is:

<?xml version="1.0" encoding="utf-8"?>05



Cheers,
Dimitre Novatchev.




__________________________________________________
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
http://fifaworldcup.yahoo.com

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


Current Thread