xslt 输入控件不基于数据设置
xslt input control not setting base on data
我有正在与此 xslt 文件一起使用的数据,但我无法获取 Selected true
来设置要检查的输入收音机。这是检查 test="Selected = true"
以设置该属性的正确逻辑吗?
数据
<CustomerGender>
<CustomerGender>
<Value>802</Value>
<Text>Female</Text>
<Selected>false</Selected>
</CustomerGender>
<CustomerGender>
<Value>803</Value>
<Text>Male</Text>
<Selected>false</Selected>
</CustomerGender>
<CustomerGender>
<Value>804</Value>
<Text>Non-binary</Text>
<Selected>true</Selected>
</CustomerGender>
<CustomerGender>
<Value>805</Value>
<Text>Prefer not to answer</Text>
<Selected>false</Selected>
</CustomerGender>
<CustomerGender>
<Value>806</Value>
<Text>Other (please specify)</Text>
<Selected>false</Selected>
</CustomerGender>
</CustomerGender>
XSLT
<div class="col-md-5">
<label class="control-label">Gender</label>
<div class="form-group">
<div class="radio-list">
<label>
<xsl:for-each select ="Customer/CustomerGender/CustomerGender">
<input type="radio" name="selectedGender">
<xsl:attribute name="id" >
<xsl:value-of select="Value"/>
</xsl:attribute>
<xsl:attribute name="value">
<xsl:value-of select="Value"/>
</xsl:attribute>
<xsl:if test="Selected = true">
<xsl:attribute name="checked">"checked"</xsl:attribute>
</xsl:if>
<xsl:value-of select="Text"/>
</input>
   <br />
</xsl:for-each>
</label>
</div>
</div>
</div>
你的路线
<xsl:if test="Selected = true">
作品是:
- 测试是一个 xpath 表达式
Selected
是子轴上的元素名称
- 这部分将 return 包含名称为
Selected
的所有元素的节点列表
- 然后它将测试该值是否与由 'true'
编辑的节点列表 return 相同
不是你想要的。你可以做类似
的事情
<xsl:if test="Selected = true()">
<xsl:if test="Selected">
- 它将测试该值是否为布尔值 true
- 为此the nodelist has to be converted to boolean, which is true if the nodelist is not empty
- 因为在你的 none 次迭代中有一个
CustomerGender
没有 Selected
它总是正确的
所以你可能想把它改成
<xsl:if test="Selected = 'true'">
这将执行字符串比较。另一种选择是
<xsl:if test="Selected[1] = 'true'">
这会将第一个找到的元素转换为字符串(得到文本内容),然后进行比较,或者
<xsl:if test="Selected[1] = true()">
<xsl:if test="Selected[1]">
这会将第一个元素转换为布尔值(现在我迷路了......)
我有正在与此 xslt 文件一起使用的数据,但我无法获取 Selected true
来设置要检查的输入收音机。这是检查 test="Selected = true"
以设置该属性的正确逻辑吗?
数据
<CustomerGender>
<CustomerGender>
<Value>802</Value>
<Text>Female</Text>
<Selected>false</Selected>
</CustomerGender>
<CustomerGender>
<Value>803</Value>
<Text>Male</Text>
<Selected>false</Selected>
</CustomerGender>
<CustomerGender>
<Value>804</Value>
<Text>Non-binary</Text>
<Selected>true</Selected>
</CustomerGender>
<CustomerGender>
<Value>805</Value>
<Text>Prefer not to answer</Text>
<Selected>false</Selected>
</CustomerGender>
<CustomerGender>
<Value>806</Value>
<Text>Other (please specify)</Text>
<Selected>false</Selected>
</CustomerGender>
</CustomerGender>
XSLT
<div class="col-md-5">
<label class="control-label">Gender</label>
<div class="form-group">
<div class="radio-list">
<label>
<xsl:for-each select ="Customer/CustomerGender/CustomerGender">
<input type="radio" name="selectedGender">
<xsl:attribute name="id" >
<xsl:value-of select="Value"/>
</xsl:attribute>
<xsl:attribute name="value">
<xsl:value-of select="Value"/>
</xsl:attribute>
<xsl:if test="Selected = true">
<xsl:attribute name="checked">"checked"</xsl:attribute>
</xsl:if>
<xsl:value-of select="Text"/>
</input>
   <br />
</xsl:for-each>
</label>
</div>
</div>
</div>
你的路线
<xsl:if test="Selected = true">
作品是:
- 测试是一个 xpath 表达式
Selected
是子轴上的元素名称- 这部分将 return 包含名称为
Selected
的所有元素的节点列表
- 然后它将测试该值是否与由 'true' 编辑的节点列表 return 相同
不是你想要的。你可以做类似
的事情<xsl:if test="Selected = true()">
<xsl:if test="Selected">
- 它将测试该值是否为布尔值 true
- 为此the nodelist has to be converted to boolean, which is true if the nodelist is not empty
- 因为在你的 none 次迭代中有一个
CustomerGender
没有Selected
它总是正确的
所以你可能想把它改成
<xsl:if test="Selected = 'true'">
这将执行字符串比较。另一种选择是
<xsl:if test="Selected[1] = 'true'">
这会将第一个找到的元素转换为字符串(得到文本内容),然后进行比较,或者
<xsl:if test="Selected[1] = true()">
<xsl:if test="Selected[1]">
这会将第一个元素转换为布尔值(现在我迷路了......)