Groups | Blog | Home
all groups > dotnet xml > april 2005 >

dotnet xml : XSLT Question


Philipp Schumann
4/20/2005 4:47:02 PM
Hi,

I'm using .NET Framework 1.1 XSLT.

Can anyone tell me why this works:

<xsl:for-each select="$somenodelist">
<xsl:if test="ext:CheckCondition (@condition)">Bla</xsl:if>
</xsl:for-each>

But the following doesn't produce the same results - it behaves as if
CheckCondition (a custom function that returns System.Boolean) would
_always_ return true:

<xsl:for-each select="$somenodelist [ext:CheckCondition (@condition)]">
Bla
</xsl:for-each>

What's the point of the square brackets then ... I thought it would be "set
restriction" that in the end evaluates to a boolean condition which is then
probed by the XSLT processor?

Thanks,
Phil

BTW, I've also played around with variants:
$somenodelist [ext:CheckCondition (@condition) = true ()]
$somenodelist [boolean (ext:CheckCondition (@condition))]
$somenodelist [boolean (ext:CheckCondition (@condition)) = true ()]
$somenodelist [string (ext:CheckCondition (@condition)) = 'true']

etc.

Oleg Tkachenko [MVP]
4/21/2005 12:00:00 AM
[quoted text, click to view]

Sould be working actually. Please provide some repro. Here is small
test, which works fine:

XML:
<data>
<row>1</row>
<row>2</row>
<row>3</row>
<row>4</row>
<row>5</row>
<row>6</row>
<row>7</row>
</data>

XSL:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:user="urn:my-scripts"
exclude-result-prefixes="msxsl user">

<msxsl:script language="C#" implements-prefix="user">
<![CDATA[
public bool filter(XPathNodeIterator node){
node.MoveNext();
if (int.Parse(node.Current.Value)%2 == 0)
return true;
else
return false;
}
]]>
</msxsl:script>

<xsl:template match="data">
<data>
<xsl:for-each select="row[user:filter(.)]">
<xsl:copy-of select="."/>
</xsl:for-each>
</data>
</xsl:template>
</xsl:stylesheet>

result:
<data>
<row>2</row>
<row>4</row>
<row>6</row>
</data>


--
Oleg Tkachenko [XML MVP, MCP]
AddThis Social Bookmark Button