Connecting Tech Pros Worldwide Forums | Help | Site Map

How to Fetch the node using stylesheet

Newbie
 
Join Date: Feb 2008
Posts: 31
#1: May 21 '09
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

Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,650
#2: May 21 '09

re: How to Fetch the node using stylesheet


XPath will get you the node.
Newbie
 
Join Date: Feb 2008
Posts: 31
#3: May 21 '09

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
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,650
#4: May 21 '09

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
Newbie
 
Join Date: Feb 2008
Posts: 31
#5: May 21 '09

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>
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,650
#6: May 21 '09

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.
Newbie
 
Join Date: Feb 2008
Posts: 31
#7: May 21 '09

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>
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,650
#8: May 21 '09

re: How to Fetch the node using stylesheet


your main problem is, that you don't have any visual output.
Newbie
 
Join Date: Feb 2008
Posts: 31
#9: May 21 '09

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
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,650
#10: May 21 '09

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.
Moderator
 
Join Date: Mar 2006
Posts: 1,103
#11: May 21 '09

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']"/>
Newbie
 
Join Date: Feb 2008
Posts: 31
#12: May 22 '09

re: How to Fetch the node using stylesheet


Thanks a lot. It worked
Reply


Similar XML bytes