Treeview & XPath

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?T2xpdmllcjc3Nzc=?=

    #1

    Treeview & XPath

    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\Re port 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.

  • Martin Honnen

    #2
    Re: Treeview &amp; XPath

    Olivier7777 wrote:
    Can i resolve this using XPath or does it required XSLT ?
    I think you need XSLT:

    <xsl:styleshe et
    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 --- MVP XML
    http://JavaScript.FAQTs.com/

    Comment

    • =?Utf-8?B?T2xpdmllcjc3Nzc=?=

      #3
      Re: Treeview &amp; XPath



      "Martin Honnen" wrote:
      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'.

      Comment

      Working...