Treeview & XPath

  • Thread starter Thread starter Olivier7777
  • Start date Start date
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.
 
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>
 
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'.
 
Back
Top