Link to home
Start Free TrialLog in
Avatar of ethar turky
ethar turkyFlag for Saudi Arabia

asked on

xml xsl Unknown method. -->position()<-- != last()

Dear all
I am trying to find the index number of the node within a parent and insert code
if it isn't the LAST node.
<xsl:if test="position() != last()">

When I run the
code, I get this error:

Error Unknown method. -->position()<-- at MSXML2.IXMLDOMDocument2.transformNode(IXMLDOMNode stylesheet) at ...

the code in c#:
MSXML2.XSLTemplate DOMDocument30= new MSXML2.DOMDocument30();

Open in new window


Any ideas?
Avatar of Gertone (Geert Bormans)
Gertone (Geert Bormans)
Flag of Belgium image

please show us the full XSLT

note that
<xsl:if test="not(position() = last())">
is a better test

but I fear you are having the wrong namespace in your XSLT
Avatar of ethar turky

ASKER

I am using
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">

Open in new window

and cant change it.
That is what I suspected.

I respect that you can't change that, but....

you are about the only person I know that is still using the Working Draft XSL,
(support has been dropped over 10 years ago)
so please, in future XSLT questions, start by mentioning that context.
There are very few that have the historical background to help you with this
and I think that books or tutorials have long vanished from the internet.

position() definitely is simply not supported and I don't remember the alternative by heart

I will try to dig up some old course material I have left, maybe I can find an answer...
if not, start thinking about migration... because using the old WD-XSL will really be hard to maintain
ASKER CERTIFIED SOLUTION
Avatar of Gertone (Geert Bormans)
Gertone (Geert Bormans)
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ok, thanks,
I found this
<xsl:if test="context()[not(end())]"></xsl:if>

Open in new window


do you know any practical way to do transformation , its a huge xsl file
yes, you told me it is huge.

The best "first step" would be an XSLT that does the bulk of the work.
The example you had earlier does some of the work, but it is a far from perfect project.
I am not aware of other projects that do the same

Personally I would develop XSLTs that do seperate steps
- first pull out all the javascript function, evaluate them and redo them when necessary to put in  a script element, others that are now ms xtension functions or existing xslt1 functions
- transform the clean WD-XSL to XSLT1
- put the functions back in

But this requires some knowledge of both WD-XSL and XSLT1
the current xsl is very simple not more then :
<xsl:for-each select="xxxx" order-by="@yyyy">
xsl:value-of select="@Name"/> 

Open in new window

Here is very basic & simple xsl witch failed to converted by suggest MS file (xsl-xslt-converter.xslt)

c# code:
			XsltSettings mySettings = new XsltSettings();
			mySettings.EnableScript = true;
			XslCompiledTransform xslt = new XslCompiledTransform();
			xslt.Load(Server.MapPath(@"xsl-xslt-converter.xslt"), mySettings , null); //
			xslt.Transform(Server.MapPath(@"Thefile.xsl"), Server.MapPath(@"Thefile.xslt"));

Open in new window


Thefile.xml:
<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
		<xsl:template match="/">
		<xsl:for-each select="Community/Person[@GInclude='true']">
			<File>
				<xsl:attribute name="name">
					<xsl:value-of select="@Name"/>.txt
				</xsl:attribute><xsl:attribute name="PersonName">
					<xsl:value-of select="@Name"/>
				</xsl:attribute>
				<xsl:for-each select="Members">					
					<xsl:apply-templates select="."/>
				</xsl:for-each>
				 
			</File>
		</xsl:for-each>
	</xsl:template>	
</xsl:stylesheet>

Open in new window

first make sure that the mini WD-xsl you made is valid WD-XSL
make a test run a view the results
(I am not certain all constructs are valid, but have to admit that my WD-xsl is rusty)

then make sure you find a way to catch the error messages
(running from stylus studio, xml spy or command line makes more sense for debugging than running from code, I remember having told you that before)

If this were my project, I would certainly make an XSLT2 of the xsl-xslt-converter.xslt which would lead to cleaner and robuster code, and would do proper debugging in Oxygen or stylus studio
You need to know that the converter that you are using is a one person project, fit for his personal requirements, and there is quiet a bit of finetuning required to use it in a general context

I think you need to make some hard decissions at some point = invest in a proper migration of the 10k lines. Maybe you need to start thinking about redoing that project from the specs. In the long run that will be the cheapest option. You have been fighting with this code for over a year now as far as I remember. You have my private email address. You could send me an NDA, I can sign that and after you send me the WD-XSL, some source and some results documents. So can propose a best approach to migration
ok, what about the example I give?
why its not working?
not sure, that is why I gave you two steps to try
 "first" and "then"
Not set up to do debugging for you