简体   繁体   English

从XSL中的XML文件中提取单个元素的值

[英]Extract value of single element from XML file in XSL

I have below xml file and i want to extract a single element from any node, 我有下面的xml文件,我想从任何节点中提取单个元素,

<?xml version="1.0" encoding="UTF-8"?>
<root>
    <SubRoot>
        <type>A</type>
        <mand>Y</mand>
        <Section>B</Section>
    </SubRoot>
    <SubRoot>
        <type>B</type>
        <mand>Y</mand>
        <Section>A</Section>
    </SubRoot>
</root>

From the above xml file how can i get the value of type element from any SubRoot node in XSL.And number of SubRoot node is unknown.it can be one,two,three or more than three. 从上面的xml文件中,我如何从SubRoot中的任何SubRoot节点获取type元素的值。 SubRoot节点的数目是SubRoot的。它可以是一个,两个,三个或三个以上。 I don't want to use the template and for each loop. 我不想使用模板和每个循环。

i tried something as below but i am not getting any value 我尝试了以下内容,但没有任何价值

<xsl:if test="(/root/SubRoot/[Section = 'B'])">
 <xsl:value-of select="/root/SubRoot/@type"/>
 </xsl:if>

Please suggest me some approach.Any suggesstion and solution must be appreciated. 请建议我一些方法。任何建议和解决方案都必须感谢。

Suppose i want to select type from second node 假设我要从第二个节点中选择类型

Use: 采用:

<xsl:value-of select="/root/SubRoot[2]/type"/>

to extract the type value from the second SubRoot node. 从第二个SubRoot节点提取type值。


Judging from your attempt, you want the type value from the SubRoot node where Section has the value of "B". 从您的尝试来看,您需要SubRoot节点(其中Section的值为“ B”)的type值。 For this, use: 为此,请使用:

<xsl:value-of select="/root/SubRoot[Section='B']/type"/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM