2010-06-29 93 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}"/>