如何使用 <xsl:if> 检查 xml 节点名称
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14995732/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to check xml node names using <xsl:if>
提问by user1602243
I am having an xml file that goes like this.
我有一个像这样的 xml 文件。
<RootTag>
<Form>
<Section>
<Annex>
<Group>
<Label value = "Name"></Label>
<Text Value = "Enter Name"></Text>
</Group>
<Group>
<Label value = "Gender"></Label>
<Radio Value = "Male||Female"></Text>
</Group>
</Annex>
</Section>
</Form>
</RootTag>
Now in my xsl, I have to check if the tag is <Text>or <Radio>and generate <input>tag based on that result.
现在在我的 xsl 中,我必须检查标签是否为<Text>或<Radio>并<input>根据该结果生成标签。
Is there any whay I can do it using <xsl:if>? Like <xsl:if test = 'node = <Text>'>
有什么我可以使用的方法<xsl:if>吗?喜欢<xsl:if test = 'node = <Text>'>
回答by
<xsl:if test="name() = 'Form'">
However, there are other approaches which may be better:
但是,还有其他方法可能更好:
One is to use a template for this item; the XSLT engine will automatically perform the test, if you want to look at it that way.
一个是使用这个项目的模板;XSLT 引擎将自动执行测试,如果您想这样看的话。
<xsl:template match="Form">
Another is to use the self::axis
另一种是使用self::轴
<xsl:for-each select="self::Form">

