Treeview & XPath

O

Olivier7777

Hi,

I have an issue displaying data with the treeview control.

Here is my xml file :

<ROOT>
<FOLDER>
<MODEL>
<REPORT>
<MARKER id="1" />
</REPORT>
</MODEL>
<MODEL>
<REPORT>
<MARKER id="2" />
</REPORT>
</MODEL>
</FOLDER>
</ROOT>

How to obtain this tree : Folder\Model\Report using the ID of the MARKER
element ?

I've tried with /FOLDER[MODEL/REPORT/MARKER/@id='1']

This woks fine concerning the tree display but not for the selected data :
the 2nd REPORT element with the id MARKER equals to 2 is included (logical
but annoying ;-).

An with this /FOLDER/MODEL/REPORT[MARKER/@id='1'] it is the contrary :
selection is ok but i loose FOLDER and MODEL nodes.

Can i resolve this using XPath or does it required XSLT ?


Thanks.
 
M

Martin Honnen

Olivier7777 said:
Can i resolve this using XPath or does it required XSLT ?

I think you need XSLT:

<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">

<xsl:param name="id" select="1"/>

<xsl:template match="ROOT">
<xsl:apply-templates select="FOLDER"/>
</xsl:template>

<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>

<xsl:template match="MODEL">
<xsl:if test="REPORT/MARKER/@id = $id">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:if>
</xsl:template>

</xsl:stylesheet>
 
O

Olivier7777

Martin Honnen said:
I think you need XSLT:

I was pretty sure but ... you never know.
Anyway thank you for the example because i'm not very familiar with XSLT and
it will help me a lot to begin. So i gonna try to build this dynamically and
will come back if i'd turn in circle.
Have a nice day.

Oliv'.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Messy TreeView Results 11
Constructing XPath Query 2
Treeview problem 0
XPath 3
ASP.NET 2.0 TreeView - Programatically Selecting A TreeView Node 2
TreeView Postback 0
XPath and nodes? 1
Databound TreeView 2

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,067
Latest member
HunterTere

Latest Threads

Top