【发布时间】:2014-10-10 09:24:02
【问题描述】:
如果使用 XML 和 XSLT 未选择微调器中的选项,如何隐藏其他字段?
例如,我有一个带有三个选项的微调器
Option 1: Form 1
Option 2: Form 2
Option 3: Others
如果用户选择选项 1,选项 1 下的所有字段都会显示,而选项 2 下的字段会隐藏(反之亦然)
这对吗?
<xsl:template match="/">
<xsl:apply-templates select="Form/Field">
<xsl:variable name="Category" select="Spinner"/>
<select id="Form">
<xsl:for-each select="$Item">
<xsl: value="{.}">
<xsl:attribute name="type"/>
</xsl:if>
<xsl:value-of select="."/>
</xsl:template>
XML:
<Field name="Category" type="Spinner" label="Please choose">
<Item code="CashPickupForm" label="Cash Pickup"/>
<Item code="HomeVisitForm" label="Home Visit"/>
<Item code="OtherForm" label="Others"/>
</Field>
这是表格 1 的一些 XML
<Form name="CashPickup"
type="TextView"
label="Cash Pick-up Form">
<Field name="ContractNumber" type="TextView" label="Contract number" value=""/>
<Field name="ClientName" type="TextView" label="Client Name" value=""/>
<Field type="Delimiter"/>
XSL:
<xsl:template match="/">
<xsl:apply-templates select="Form"/>
</xsl:template>
<xsl:template match="Form">
<xsl:element name="Form">
<xsl:attribute name="name">
<xsl:value-of select="@name"/>
</xsl:attribute>
<xsl:attribute name="type">
<xsl:value-of select="@type"/>
</xsl:attribute>
<xsl:attribute name="label">
<xsl:value-of select="@label"/>
</xsl:attribute>
<xsl:copy-of select="namespace::*[not(name()='ns2') and not(name()='')]"/>
<xsl:call-template name="Arrange"/>
</xsl:element>
</xsl:template>
<xsl:template name="Arrange">
<xsl:apply-templates select="Field[@name='ContractNumber']"/>
<xsl:apply-templates select="Field[@name='ClientName']"/>
<Field type="Delimiter"/>
XML 表格 2:
<Form name="HomeVisitForm"
type="TextView"
label="Home Visit Form">
<Field name="ContractNumber" type="TextView" label="Application number" value=""/>
<Field name="TypeCheck" type="TextView" label="Type of check" value=""/>
<Field type="Delimiter"/>
XSL:
<xsl:template match="/">
<xsl:apply-templates select="Form"/>
</xsl:template>
<xsl:template match="Form">
<xsl:element name="Form">
<xsl:attribute name="name">
<xsl:value-of select="@name"/>
</xsl:attribute>
<xsl:attribute name="type">
<xsl:value-of select="@type"/>
</xsl:attribute>
<xsl:attribute name="label">
<xsl:value-of select="@label"/>
</xsl:attribute>
<xsl:copy-of select="namespace::*[not(name()='ns2') and not(name()='')]"/>
<xsl:call-template name="Arrange"/>
</xsl:element>
</xsl:template>
<xsl:template name="Arrange">
<xsl:apply-templates select="Field[@name='ContractNumber']"/>
<xsl:apply-templates select="Field[@name='TypeCheck']"/>
<Field type="Delimiter"/>
【问题讨论】:
-
您找到解决方案了吗?如果是这样,请删除该问题,因为它在当前状态下有点不稳定。如果没有,请发表评论,我们可以尝试为您的问题添加大量信息,以供回答。
-
还没有。我仍在为这个@MarcusRickert 寻找解决方案
-
好的。所以这些是我最初的问题/建议:在提供 XML 文件时,请确保您声明为 Source XML(您的输入)或 Target XML(所需的输出)。您应该只有一个 XSLT(目前您有两个 sn-ps)。您的 XML 文件有不平衡的标签。你能仔细检查一下吗?要使 XSLT 对当前选择做出反应,您必须将此选择存储在变量中的某个位置。将此选择传递给 XSLT 的首选方式是什么?参数?
-
@MarcusRickert 是的,尽可能通过参数
-
我的其他问题/cmets呢?
标签: xml xslt xml-parsing show-hide