2010-06-29 55 views
0

我想发送一个编码为application/x-www-form-urlencoded的消息,并且该消息由XML模式验证,所以我找到了一种方法可以从XML生成一个html表单使用XSLT的模式。从XML模式生成表单键

的XSD低于:

<?xml version="1.0" encoding="UTF-8"?> 
<xs:schema xmlns:xs="http://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> 

和XSLT下面是:

<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> 

结果是:

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

但我不能找到一种方法,从xsd设置输入名称,还是应该使用javascript?

回答

1

尝试:

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

(见W3C specifications

顺便说一句,你可以用xs:annotation/xs:appInfo添加有关更好看标签,上下文帮助等信息......

1

你有几种选择:

使用xsl:attribute

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

使用快捷(属性值模板):

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