Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / March 2008

Tip: Looking for answers? Try searching our database.

Treeview & XPath

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Olivier7777 - 07 Mar 2008 10:11 GMT
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.
Martin Honnen - 07 Mar 2008 13:53 GMT
> 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>

Signature

    Martin Honnen --- MVP XML
    http://JavaScript.FAQTs.com/

Olivier7777 - 08 Mar 2008 09:38 GMT
> 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'.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.