从XSLT文件渲染表单

时间:2010-06-07 17:43:48

标签: asp.net-mvc xml xslt parameters

我已经生成了以下XSLT文件,并创建了一个Form,该Form将发布到名为Home / ProcessRequest的ASP.Net MVC操作中:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
>
<xsl:output method="html" indent="yes"/>

<xsl:template match="/">
<html>
<body>
<xsl:value-of select="Employee/Name"/>
  <br />
  <xsl:value-of select="Employee/ID"/>        
<form method="post" action="/Home/ProcessRequest?id=42">
  <input id="Action" name="Action" type="radio" value="Approved"></input>  Approved    <br />
  <input id="Action" name="Action" type="radio" value="Rejected"></input>  Rejected <br />
  <input type="submit" value="Submit"></input>
</form>
</body>
</html>

这是我的XML文件:

<Employee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"            xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Name>Russ</Name>
<ID>42</ID>
</Employee>

这样可以正常工作,但是我需要从硬编码整数更改my中的id参数,以使用我的XML文件中的ID元素。有谁知道怎么做?

1 个答案:

答案 0 :(得分:1)

这应该这样做:

<form method="post" action="/Home/ProcessRequest?id={Employee/ID}">

{}是在属性中使用XPath的简写。