RE: [xsl] Problem using Position() in .NET environment.

Subject: RE: [xsl] Problem using Position() in .NET environment.
From: Pieter Reint Siegers Kort <pieter.siegers@xxxxxxxxxxx>
Date: Thu, 14 Oct 2004 08:38:38 -0500
OK, so you got the solution. Now the explanation... 

Michael Kay's book says this at page 313 about what the attribute "match"
actually is in a xsl:template element:

"A pattern that determines which nodes are eligible to be processed by this
template. If this attribute is absent, there must be a nasme attribute."

You see that the 'match' attribute takes a pattern. A pattern is not like a
'select' attribute in for example xsl:apply-templates; 'select' is an
(Xpath) expression.

I would guess that giving a "//" in a match attribute, which we know now is
actually not necessary, makes the pattern somehow invalid - don't know if
this should happen or not, but now that we know, we can at least work around
it.

Cheers,
<prs/>

-----Original Message-----
From: Animesh Sharma [mailto:asharma@xxxxxxxxxxxxxxxx] 
Sent: Thursday, October 14, 2004 12:02 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: RE: [xsl] Problem using Position() in .NET environment.

Hi Pieter,

Yeah, as you mentioned second template
"match="//input[@value='go'][preceding-sibling::a[1][contains(img/@src,
'cancel')]]"
doesn't match any node in the input XML in .NET environment. 

Output(as expected) in MSXML:
<html><body><table><tbody><tr><td>
<input type="Submit" name="fr_onclick_5000000012501_fr_cands_1077;1083;"
value="Cancel"/>
</td></tr></tbody></table></body></html>

Ouput in .NET::
<html><body><table><tbody><tr><td>
<input type="submit" name="fr_onclick_5000000012501_fr_cands_1077;1083;"
value="go">
</input></td></tr></tbody></table></body></html>

Note (value) attribute of <input> node gets modified in the first case But
not in Second case. For clarity I have removed the attributes from other
node. 
My concern was to locate the position of Input node and modify its
attribute. And the problem was in the differnce in bahaviour of MSXML and
.NET XSL libraries for the same match patter.

Initially I thought position() was creatin problem. But now it seems that
this is not the case. Momemt I remove "//" from the match pattern, both
gives the same (correct) output. 
I'm bit confused. 

Thanks,
Animesh


-----Original Message-----
From: Pieter Reint Siegers Kort [mailto:pieter.siegers@xxxxxxxxxxx]
Sent: Wednesday, October 13, 2004 9:47 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: RE: [xsl] Problem using Position() in .NET environment.

Animesh, you mean the second template doesn't make a match in .NET, right?

And, I would like to see what you get using MSXML vs. XslTransform (both
output). 
Could you please post that?

BTW, like David C. comments, you can reduce your xpaths to:

<xsl:template match="a[img[contains(@src,'cancel')]]" priority="1"/>
<xsl:template
match="input[@value='go'][preceding-sibling::a[1][contains(img/@src,'can
cel'
)]]">

Does that help?

Cheers,
<prs/>

-----Original Message-----
From: Animesh Sharma [mailto:asharma@xxxxxxxxxxxxxxxx]
Sent: Wednesday, October 13, 2004 10:08 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: RE: [xsl] Problem using Position() in .NET environment.

Hi,

Yeah, I'm using XSLTransform class of .NET framework.

My inputXSL:
<xsl:template match="//a[img[contains(@src,'cancel')]]" priority="1"/>
	<xsl:template
match="input[@value='go'][preceding-sibling::a[position()=1][contains(im
g/@src,'cancel')]]">
		<xsl:copy>
			<xsl:apply-templates select="@*"/>
			<xsl:attribute
name="type">Submit</xsl:attribute>
			<xsl:attribute
name="value">Cancel</xsl:attribute>
			<xsl:apply-templates select="*|text()"/>
		</xsl:copy>
	</xsl:template>
<!--Default Copy template -->
	<xsl:template match="*|text()|@*">
		<xsl:copy>
			<xsl:apply-templates select="*|text()|@*"/>
		</xsl:copy>
	</xsl:template>

InputXML:
<?xml version="1.0"?>
<html><body>		
<table bgcolor="#336699" width="98%" border="0" cellpadding="2"
cellspacing="0" style="margin-top: 10px;"> <tbody><tr> <td align="right"
fr_option="dynamic" fr_cands="1077;1083;"> <a href="http://10.0.3.214:8080";
onmouseover="" onmouseout=""> <img
src="http://myprod.concureworkplace.com/ewp/Images/entrycancel.gif";
alt="Cancel" border="0" title="Cancel"/> </a> <input type="submit"
name="fr_onclick_5000000012501_fr_cands_1077;1083;"
value="go"/>
</td></tr></tbody></table></body></html>

And the problem is that in .NET above template doesn't match. 

Thanks,
Animesh



-----Original Message-----
From: Pieter Reint Siegers Kort [mailto:pieter.siegers@xxxxxxxxxxx]
Sent: Wednesday, October 13, 2004 8:28 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: RE: [xsl] Problem using Position() in .NET environment.

Hi Animesh,

Do you use the XslTransform?

Then you say:
> When I remove position() from Xpath above, it works.

So what's the problem then? Just kidding, I guess you still have a problem,
just send in some representative XML, your XSL, and what output you need.
We'll be able to help you better.

I have found this MS-KB article, it may not apply to your expression, cause
you're not using postion() as a function parameter, but still it may well be
a (another) bug:
http://support.microsoft.com/default.aspx?scid=kb;en-us;324033

HTH,
<prs/>

-----Original Message-----
From: Animesh Sharma [mailto:asharma@xxxxxxxxxxxxxxxx]
Sent: Wednesday, October 13, 2004 9:36 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: [xsl] Problem using Position() in .NET environment.

Hi,

I'm not sure whether this problem belongs to this group or not. 
But I'm facing very peculiar problem in .Net (version 1.1) environment.

Following XSL works with MSXML4 but NOT with .Net XSL translator:

<xsl:template
match="//input[@value='go'][preceding-sibling::a[position()=1][contains(
img/@src,'cancel')]]">

<--Do Some operation>

</xsl:template>

When I remove position() from Xpath above, it works.
I'm unable to figure out the problem. If anyone knows the solution, do let
me know.

Thanks,
Animesh

Current Thread