一个关于xlst自定义函数返回值的问题

tarius 2003-09-12 02:49:14
刚学习xml + xslt,需要在xslt里写一些自定义的函数,发现传入参数可以通过
<xsl:template name="myfunction">
<xsl:param name="para1">1</xsl:param>
.......
.......
.......
</xsl:template>

<xsl:call-template name="myfunction">
<xsl:with-param name="para1">2</xsl:with-param>
</xsl:call-template>

实现,但是如果在myfunction自定义函数里面处理的结果,怎么样才能返回呢?
怎么样才能实现我们平时编程时的自定义函数效果?
int myfunction(int para1)
{
.........
.........
return 3;
}

int pp = myfunction(2);

xslt的编程思路与普通语言的思路有很大的不同,苦恼!!
...全文
163 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
孟子E章 2003-09-14
  • 打赏
  • 举报
回复
xslt函数??like this??
<xsl:value-of select="substring(nodewName,0,10)"/>
Kyle_Chen 2003-09-14
  • 打赏
  • 举报
回复
<xsl:template name="func1">
<xsl:param name="p1" select="'abc'" />

<xsl:value-of select="$p1" />

</xsl:template>

<!-- we'll call template "func1" in the following template.
and use the return value -->
<xsl:template name="func2">

<xsl:variable name="func1return">
<xsl:call-template name="func1">
<xsl:with-param name="p1" select="'test'" />
</xsl:call-template>
</xsl:variable>

<!-- variable '$func1return' would contain the return of
the template func1 -->

</xsl:template>
孟子E章 2003-09-13
  • 打赏
  • 举报
回复
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="script.xsl" ?>
<customers>
<customer>
<name>John Smith</name>
<address>123 Elm St.</address>
<phone>(123) 456-7890</phone>
</customer>
<customer>
<name>Mary Jones</name>
<address>456 Oak Ave.</address>
<phone>(156) 789-0123</phone>
</customer>
</customers>


script.xsl
<?xml version='1.0'?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:user="http://mycompany.com/mynamespace">

<msxsl:script language="JScript" implements-prefix="user">
function xml(nodelist) {
return nodelist.nextNode().text;
}
</msxsl:script>

<xsl:template match="/">
<xsl:value-of select="user:xml(.)"/>
</xsl:template>

</xsl:stylesheet>
tarius 2003-09-13
  • 打赏
  • 举报
回复
高!!通过js取得xslt函数的返回值。
有没有方法在xslt里面取得xslt函数的返回值?
ssm1226 2003-09-12
  • 打赏
  • 举报
回复
在哪使用此函数据?XSLT里?

8,906

社区成员

发帖
与我相关
我的任务
社区描述
XML/XSL相关问题讨论专区
社区管理员
  • XML/XSL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧