Question

Let's say I have an XML hierarchy that looks similar to this:

<Animal>
    <Kingdom>
        <Phylum>
            <Class></Class>
            <Class></Class>
        </Phylum>
        <Phylum>
            <Class></Class>
            <Class></Class>
        </Phylum>
    </Kingdom>
    <Kingdom>
        <Phylum>
            <Class></Class>
            <Class></Class>
        </Phylum>
    </Kingdom>
</Animal>

(etc.)

Likewise, I have ASP.NET code using nested repeaters, something like this:

<asp:Repeater ID="ShowKingdom" runat="server" DataSource="(SomeDataSource)">
    <ItemTemplate>
        <asp:TextBox ID="txtKingdom" runat="server" XPath="/*[local-name()='Animal']/*[local-name()='Kingdom'][{0}]">
        <asp:Repeater ID="ShowPhylum" runat="server" OnItemDataBound="(SomeDataBinder)">
            <ItemTemplate>
                <asp:TextBox ID="txtKingdom" runat="server" XPath="/*[local-name()='Animal']/*[local-name()='Kingdom'][{0}]/*[local-name()='Phylum'][???]">
            </ItemTemplate>
        </asp:Repeater>
    </ItemTemplate>
</asp:Repeater>

My problem: how do I specify the node index selector "[???]" for the XPath inside the nested repeater?!?

Note: my language is VB within ASP.NET.

Edit: I've tried using a different index "[{1}]" (gives me an index out-of-bounds error), a relative Xpath "[local-name()='Phylum']" (no "/*" preceding it -- does not recognize the node/path), and tinkering with the nested repeater data source (it either doesn't recognize the XPath or crashes).

Obviously, I haven't been able to get any of these to work. Do I need to consider another approach?

Edit #2: Another thing I tried that does not want to work: for the nested repeater:

DataSource="<%# XPathSelect('Phylum')%>"
Was it helpful?

Solution

I finally figured this out. I found the key here.

After doing a lot of digging, I realized that my {0} predicate index in my XPath was being replaced in the code-behind using a call to String.format.

I obtained the parent repeater index by referencing e.Item.Parent.Parent (where "e" is a RepeaterItemEventArgs object).

Once I had the indexes for both the current repeater and its parent, I was able to use {0} and {1} for my indexes, and the String.format did the rest.

Voila. Problem solved.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top