开发者

XPath for 0-* child level

I have following XML-File:

<?xml version="1.0" encoding="UTF-16"?>
<Export>
    <Folder ID="1004">
        <Object ID="124" Name="NameABC" />
    </Folder>
    <Folder ID="1016">
       <Folder Name="B">
            <Object ID="124" Name="Name1" />
                <Folder Name="A">
                    <Object ID="121244" Name="Name2" />
                    <Object ID="122134" Name="Name12" />
                    <Folder Name="KS">
                        <Object ID="667" Name="Name43" />
                    </Folder>
                </Folder>
        </Folder>
    </Folder>
</Export>
开发者_如何学Go

Now I need to get all <Object>'s under which have a ID and a NAME. Sometimes there is 0 Folder under the first Folder with the ID 1016 and sometimes 4.

I need to use a XPath expression. I hope you can help me. Thanks.


//folder[@ID='some_id' and @Name='some_name']/descendant::*

See:

XPath for 0-* child level


<xsl:apply-templates select="//Object">
   <xsl:value-of select="@ID"/> - <xsl:value-of select="@Name"/>
</xsl:apply-templates>

will match all <Object> elements and output the ID and Name attribute values.

The descendant selector is (from the documentation) // is short for /descendant-or-self::node()/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜