Connecting Tech Pros Worldwide Help | Site Map

How to Fetch the node using stylesheet

  #1  
Old May 21st, 2009, 10:28 AM
Newbie
 
Join Date: Feb 2008
Posts: 31
Hi All,

I am having xml in following format
Expand|Select|Wrap|Line Numbers
  1. <Form>
  2.  
  3. <Panel id="1" name="t1">
  4.     <Field1/>
  5.    <Field2/>
  6. </Panel>
  7.  
  8. <Panel id="2" name="t2">
  9.     <Field1/>
  10.    <Field2/>
  11. </Panel>
  12.  
  13. </Form>
Now my requirement is to fetch the Panel node with id="2" by using xslt for further processing for component.

Can anybody let me know how to fetch the node using XSLT?

Regards
Amol Lokhande

Last edited by Dormilich; May 21st, 2009 at 10:57 AM. Reason: Please use [code] tags when posting code
  #2  
Old May 21st, 2009, 10:59 AM
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,485
Provided Answers: 9

re: How to Fetch the node using stylesheet


XPath will get you the node.
  #3  
Old May 21st, 2009, 11:04 AM
Newbie
 
Join Date: Feb 2008
Posts: 31

re: How to Fetch the node using stylesheet


Hi,

I have written following xslt but it is not returning me the required output

Expand|Select|Wrap|Line Numbers
  1. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" version="1.0">
  2.  
  3. <xsl:template match="/">
  4.     <xsl:call-template name ="GetPanelNode">
  5.     </xsl:call-template>
  6. </xsl:template>
  7.  
  8. <xsl:template name="GetPanelNode" match="*">
  9.     Test
  10.      <xsl:value-of select="//Form/Data/Panel[@id='2']/node()"/>
  11.      Test
  12. </xsl:template>
  13. </xsl:stylesheet>

Regards
Amol Lokhande

Last edited by Dormilich; May 21st, 2009 at 11:05 AM. Reason: Please use [code] tags when posting code
  #4  
Old May 21st, 2009, 11:06 AM
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,485
Provided Answers: 9

re: How to Fetch the node using stylesheet


there's no such element as <Data> present in your XML

further, there are no visible data in your XML, so you can't see (even if you successfully selected) the node
  #5  
Old May 21st, 2009, 11:10 AM
Newbie
 
Join Date: Feb 2008
Posts: 31

re: How to Fetch the node using stylesheet


Sorry that was typo mistake

Expand|Select|Wrap|Line Numbers
  1. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" version="1.0">
  2.  
  3. <xsl:template match="/">
  4.     <xsl:call-template name ="GetPanelNode">
  5.      </xsl:call-template>
  6.  </xsl:template>
  7.  
  8. <xsl:template name="GetPanelNode" match="*">
  9. <xsl:value-of select="//Form/Panel[@id='2']/node()"/>
  10.  
  11.  </xsl:template>
  12. </xsl:stylesheet>

Last edited by Dormilich; May 21st, 2009 at 11:12 AM. Reason: Please use [code] tags when posting code
  #6  
Old May 21st, 2009, 11:13 AM
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,485
Provided Answers: 9

re: How to Fetch the node using stylesheet


see the edited comment above

further, please use [code] tags when posting code, makes it easier to read.
  #7  
Old May 21st, 2009, 11:18 AM
Newbie
 
Join Date: Feb 2008
Posts: 31

re: How to Fetch the node using stylesheet


Ok, here is the stylesheet

Expand|Select|Wrap|Line Numbers
  1. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" version="1.0">
  2.  
  3. <xsl:template match="/">
  4. <xsl:call-template name ="GetPanelNode">
  5. </xsl:call-template>
  6. </xsl:template>
  7.  
  8. <xsl:template name="GetPanelNode" match="*">
  9.       <xsl:value-of select="//Form/Panel[@id='2']/node()"/>
  10.   </xsl:template>
  11.  </xsl:stylesheet>
  #8  
Old May 21st, 2009, 11:20 AM
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,485
Provided Answers: 9

re: How to Fetch the node using stylesheet


your main problem is, that you don't have any visual output.
  #9  
Old May 21st, 2009, 11:24 AM
Newbie
 
Join Date: Feb 2008
Posts: 31

re: How to Fetch the node using stylesheet


Hi,

I am not getting you. I am testing this stylesheet againt the xml using the transformation in Vb application which is not returning any xml data

Regards
Amol Lokhande
  #10  
Old May 21st, 2009, 11:32 AM
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,485
Provided Answers: 9

re: How to Fetch the node using stylesheet


XSLT is used to transfer one XML into another (or text), so XSLT's return value is a string. the string contains everyting that XSLT "would print" to the screen.

if you don't "write" anything there will only be an empty return.

in your example the only output can come from the <Panel> nodes, but because they contain no text, thus no output and no return string.
  #11  
Old May 21st, 2009, 08:50 PM
Moderator
 
Join Date: Mar 2006
Posts: 1,103

re: How to Fetch the node using stylesheet


Are you trying to copy the entire node? You might want to use copy-of instead of value-of.
Expand|Select|Wrap|Line Numbers
  1. <xsl:copy-of select="//Form/Panel[@id='2']"/>
  #12  
Old May 22nd, 2009, 06:37 AM
Newbie
 
Join Date: Feb 2008
Posts: 31

re: How to Fetch the node using stylesheet


Thanks a lot. It worked
Reply


Similar Threads
Thread Thread Starter Forum Replies Last Post
Removing the xmlns attribute from the DOM Simon Hart answers 7 May 14th, 2006 03:25 PM