如何用XML写一按钮(Button),并赋给其一个标签?

yangj_bare 2002-07-03 10:59:36
如何用XML写一按钮(Button),并赋给其一个标签?
...全文
499 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
saucer 2002-07-03
  • 打赏
  • 举报
回复
1.
<GUI>
<button>Click Me</button>
<content>Hello World</content>
</GUI>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<head>
<script language="javascript">
<![CDATA[
function sayHello(str)
{
alert(str);
}
]]>
</script>
</head>
<body>
<xsl:apply-templates select="GUI/button" />
</body>
</html>
</xsl:template>
<xsl:template match="button">
<input type="{name()}" value="{.}" onclick="sayHello('{/GUI/content}')" />
</xsl:template>

</xsl:stylesheet>

or

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<head>
<script language="javascript">

function sayHello()
{
alert('<xsl:value-of select="GUI/content" />');
}

</script>
</head>
<body>
<xsl:apply-templates select="GUI/button" />
</body>
</html>
</xsl:template>
<xsl:template match="button">
<input type="{name()}" value="{.}" onclick="sayHello()" />
</xsl:template>

</xsl:stylesheet>
JollyFred 2002-07-03
  • 打赏
  • 举报
回复
如果点击Button的内容也在XML文件里呢,也就是显示的那个"Hello"也是从XML文件中读出来的,那应该怎么写?
saucer 2002-07-03
  • 打赏
  • 举报
回复
you need to transform XML into html, for example

1.xml:
<?xml-stylesheet type="text/xsl" href="1.xsl" ?>
<GUI>
<button>Click Me</button>
</GUI>

1.xsl:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<head>
<script language="javascript">
<![CDATA[
function sayHello()
{
alert("Hello");
}
]]>
</script>
</head>
<body>
<xsl:apply-templates select="GUI/button" />
</body>
</html>
</xsl:template>
<xsl:template match="button">
<input type="{name()}" value="{.}" onclick="sayHello()" />
</xsl:template>
</xsl:stylesheet>
JollyFred 2002-07-03
  • 打赏
  • 举报
回复
再麻烦问一下,如果xml文件是下面这样的,显示多个按钮,按不同的按钮显示不同的content,我知道要用for-each,但不知道具体怎么写,谢谢!

<?xml-stylesheet type="text/xsl" href="Button.xsl" ?>
<GUI>
<buttons>
<button>
<caption>Click Me 1</caption>
<content>Hello JollyFred1</content>
</button>
<button>
<caption>Click Me 2</caption>
<content>Hello JollyFred2</content>
</button>
</buttons>
</GUI>
JollyFred 2002-07-03
  • 打赏
  • 举报
回复
再麻烦问一下,如果xml文件是下面这样的,显示多个按钮,按不同的按钮显示不同的content,我知道要用for-each,但不知道具体怎么写,谢谢!

<?xml-stylesheet type="text/xsl" href="Button.xsl" ?>
<GUI>
<buttons>
<button>
<caption>Click Me 1</caption>
<content>Hello JollyFred1</content>
</button>
<button>
<caption>Click Me 2</caption>
<content>Hello JollyFred2</content>
</button>
</buttons>
</GUI>
JollyFred 2002-07-03
  • 打赏
  • 举报
回复
谢谢指点!

8,906

社区成员

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

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