How to Fetch the node using stylesheet 
May 21st, 2009, 10:28 AM
| | Newbie | | Join Date: Feb 2008
Posts: 31
| |
Hi All,
I am having xml in following format - <Form>
-
-
<Panel id="1" name="t1">
-
<Field1/>
-
<Field2/>
-
</Panel>
-
-
<Panel id="2" name="t2">
-
<Field1/>
-
<Field2/>
-
</Panel>
-
-
</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
| 
May 21st, 2009, 10:59 AM
|  | 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.
| 
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 - <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" version="1.0">
-
-
<xsl:template match="/">
-
<xsl:call-template name ="GetPanelNode">
-
</xsl:call-template>
-
</xsl:template>
-
-
<xsl:template name="GetPanelNode" match="*">
-
Test
-
<xsl:value-of select="//Form/Data/Panel[@id='2']/node()"/>
-
Test
-
</xsl:template>
-
</xsl:stylesheet>
Regards
Amol Lokhande
Last edited by Dormilich; May 21st, 2009 at 11:05 AM.
Reason: Please use [code] tags when posting code
| 
May 21st, 2009, 11:06 AM
|  | 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
| 
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 - <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" version="1.0">
-
-
<xsl:template match="/">
-
<xsl:call-template name ="GetPanelNode">
-
</xsl:call-template>
-
</xsl:template>
-
-
<xsl:template name="GetPanelNode" match="*">
-
<xsl:value-of select="//Form/Panel[@id='2']/node()"/>
-
-
</xsl:template>
-
</xsl:stylesheet>
Last edited by Dormilich; May 21st, 2009 at 11:12 AM.
Reason: Please use [code] tags when posting code
| 
May 21st, 2009, 11:13 AM
|  | 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.
| 
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 - <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" version="1.0">
-
-
<xsl:template match="/">
-
<xsl:call-template name ="GetPanelNode">
-
</xsl:call-template>
-
</xsl:template>
-
-
<xsl:template name="GetPanelNode" match="*">
-
<xsl:value-of select="//Form/Panel[@id='2']/node()"/>
-
</xsl:template>
-
</xsl:stylesheet>
| 
May 21st, 2009, 11:20 AM
|  | 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.
| 
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
| 
May 21st, 2009, 11:32 AM
|  | 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.
| 
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. -
<xsl:copy-of select="//Form/Panel[@id='2']"/>
| 
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
|  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 225,662 network members.
|