How to Fetch the node using stylesheet

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • amollokhande1
    New Member
    • Feb 2008
    • 33

    How to Fetch the node using stylesheet

    Hi All,

    I am having xml in following format
    Code:
    <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 21 '09, 09:57 AM. Reason: Please use [code] tags when posting code
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    XPath will get you the node.

    Comment

    • amollokhande1
      New Member
      • Feb 2008
      • 33

      #3
      Hi,

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

      Code:
      <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 21 '09, 10:05 AM. Reason: Please use [code] tags when posting code

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        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

        Comment

        • amollokhande1
          New Member
          • Feb 2008
          • 33

          #5
          Sorry that was typo mistake

          Code:
          <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 21 '09, 10:12 AM. Reason: Please use [code] tags when posting code

          Comment

          • Dormilich
            Recognized Expert Expert
            • Aug 2008
            • 8694

            #6
            see the edited comment above

            further, please use [code] tags when posting code, makes it easier to read.

            Comment

            • amollokhande1
              New Member
              • Feb 2008
              • 33

              #7
              Ok, here is the stylesheet

              Code:
              <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>

              Comment

              • Dormilich
                Recognized Expert Expert
                • Aug 2008
                • 8694

                #8
                your main problem is, that you don't have any visual output.

                Comment

                • amollokhande1
                  New Member
                  • Feb 2008
                  • 33

                  #9
                  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

                  Comment

                  • Dormilich
                    Recognized Expert Expert
                    • Aug 2008
                    • 8694

                    #10
                    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.

                    Comment

                    • jkmyoung
                      Recognized Expert Top Contributor
                      • Mar 2006
                      • 2057

                      #11
                      Are you trying to copy the entire node? You might want to use copy-of instead of value-of.
                      Code:
                      <xsl:copy-of select="//Form/Panel[@id='2']"/>

                      Comment

                      • amollokhande1
                        New Member
                        • Feb 2008
                        • 33

                        #12
                        Thanks a lot. It worked

                        Comment

                        Working...