开发者

generate form key from a XML schema

I want send a message encoded as application/x-www-form-urlencoded, and the message is validated by a XML schema, so i find a way to generate a html form from a XML Schema using XSLT.

the xsd is below:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http开发者_C百科://www.w3.org/2001/XMLSchema" xmlns:m="http://dongfang-   china.com#" targetNamespace="http://dongfang-china.com#" elementFormDefault="qualified" attributeFormDefault="unqualified">

    <xs:complexType name="SwitchingSchedule">       
    <xs:sequence>
        <xs:element name="endDateTime" type="xs:dateTime">

        </xs:element>
        <xs:element name="reason" type="xs:string"> 


        </xs:element>
        <xs:element name="startDateTime" type="xs:dateTime">                                                         

        </xs:element>
    </xs:sequence>
</xs:complexType>

and the xslt is below:

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"          xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-  functions">
 <xsl:output method="html"/>
  <xsl:template match="xs:schema">
  <xsl:for-each select="xs:complexType/xs:sequence/xs:element">
    <br/>
   <label><xsl:value-of select="@name"/></label>
   <input type="text" name=""/> 

  </xsl:for-each>
  </xsl:template>
</xsl:stylesheet>

the result is:

<br><label>endDateTime</label><input type="text"><br><label>reason</label><input type="text"><br><label>startDateTime</label><input type="text">

But i can't find a way to set the input name from the xsd, or should i use javascript?


Try:

<input type="text" name="{@name}"/> 

(see W3C specifications)

By the way, you can use xs:annotation/xs:appInfo to add information about better-looking labels, contextual help etc...


You have a couple of choices:

Use xsl:attribute:

<input type="text">
  <xsl:attribute name="name">
    <xsl:value-of select="@name" />  
  </xsl:attribute>
</input>

Use the short cut (attribute value template):

<input type="text" name="{@name}"/> 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜