how to display xslt output in web browser

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sisu
    New Member
    • Feb 2010
    • 16

    how to display xslt output in web browser

    here is the xml code

    Code:
    <?xml-stylesheet href="example2.xsl" type="text/xsl" ?>
    
    <?xml version="1.0" ?>
    
    <persons>
      <person username="JS1">
        <name>John</name>
        <family-name>Smith</family-name>
      </person>
      <person username="MI1">
        <name>Morka</name>
        <family-name>Ismincius</family-name>
      </person>
    </persons>
    xsl code

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
      <xsl:output method="xml" indent="yes"/> 
     
      <xsl:template match="/persons">
        <root>
          <xsl:apply-templates select="person"/> 
        </root>
      </xsl:template>
     
      <xsl:template match="person">
        <name username="{@username}">
          <xsl:value-of select="name" />
        </name>
      </xsl:template>
     
    </xsl:stylesheet>

    output required


    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <root>
      <name username="JS1">John</name>
      <name username="MI1">Morka</name>
    </root>
    Last edited by Dormilich; Feb 13 '10, 10:31 PM. Reason: Please use [code] tags when posting code
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    what’s the problem? as far as my browser tells me, the output is the desired one.

    Comment

    • sisu
      New Member
      • Feb 2010
      • 16

      #3
      only text is displayed in my browser no xml tags as mentioned in output field

      that is 'JohnMorka'

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        did you have a look at the generated* source code?

        PS. you use Internet Explorer?

        * - may require plugins/add-ons/extensions

        Comment

        • drhowarddrfine
          Recognized Expert Expert
          • Sep 2006
          • 7434

          #5
          The xml declaration in your xml file is in the wrong place. Move line 3 to line 1.

          Do I understand correctly that you want to display the element tags in the browser along with the text? The browser will not do this unless that data is supplied as CDATA. I believe that's possible to implement in the xslt file but I've not done that.

          Comment

          • sisu
            New Member
            • Feb 2010
            • 16

            #6
            I am getting the output in xsl-easy editor but while trying to run in browser only text is displayed no xml tags with it

            Comment

            • Dormilich
              Recognized Expert Expert
              • Aug 2008
              • 8694

              #7
              it’s exactly how doc said, a browser normally doesn’t show the tags (even if they are there).

              Comment

              • sisu
                New Member
                • Feb 2010
                • 16

                #8
                i am greatfull for your kind information

                thank you

                Comment

                • sisu
                  New Member
                  • Feb 2010
                  • 16

                  #9
                  i have attached a style sheet to it but style sheet not taken by rss in browser ,but in editor it takes why?

                  rssfeed source code


                  <?xml version="1.0" encoding="utf-8"?>

                  <?xsl-stylesheet href="xsltest.x sl" type="text/xsl"?>

                  <rss version="2.0">

                  <channel>

                  <title>wholesal e</title>

                  <link>http://localhost/fusionchart/rssfeed1.aspx</link>

                  <description>Th e latest whole sale report</description>

                  <copyright>Copy right 2001 - 2009 Roxy Palace Casino</copyright>

                  <language>en-us</language>
                  <guid>http://localhost/fusionchart/rssfeed12.aspx</guid>
                  <url>http://localhost/fusionchart/rssfeed12.aspx</url>
                  <title>wholesal e</title>
                  <link>http://localhost/fusionchart/rssfeed12.aspx</link>
                  <description>Th is shows up in title of link</description>
                  <item>
                  <title>XTPNR : 122.0000</title>
                  <description>12 2.0000</description>
                  <link>http://192.168.0.131/fusionchart/Default.aspx</link>
                  </item>
                  <item>
                  <title>XTPR0 : 1011.0000</title>
                  <description>10 11.0000</description>
                  <link>http://192.168.0.131/fusionchart/Default.aspx</link>
                  </item>
                  <item>
                  <title>XTPNR1 : 85.0000</title>
                  <description>85 .0000</description>
                  <link>http://192.168.0.131/fusionchart/Default.aspx</link>
                  </item>
                  <item>
                  <title>XXABK5 : 45.0000</title>
                  <description>45 .0000</description>
                  <link>http://192.168.0.131/fusionchart/Default.aspx</link>
                  </item>
                  <item>
                  <title>XXABK6 : 86.0000</title>
                  <description>86 .0000</description>
                  <link>http://192.168.0.131/fusionchart/Default.aspx</link>
                  </item>
                  <item>
                  <title>XXABK2 : 5.0000</title>
                  <description>5. 0000</description>
                  <link>http://192.168.0.131/fusionchart/Default.aspx</link>
                  </item>
                  <item>
                  <title>XXABK2 0 : 56.0000</title>
                  <description>56 .0000</description>
                  <link>http://192.168.0.131/fusionchart/Default.aspx</link>
                  </item>
                  <item>
                  <title>XXABK4 : 56.0000</title>
                  <description>56 .0000</description>
                  <link>http://192.168.0.131/fusionchart/Default.aspx</link>
                  </item>
                  <item>
                  <title>XTPNR7 : 78.0000</title>
                  <description>78 .0000</description>
                  <link>http://192.168.0.131/fusionchart/Default.aspx</link>
                  </item>
                  <item>
                  <title>XTPNR8 : 3.0000</title>
                  <description>3. 0000</description>
                  <link>http://192.168.0.131/fusionchart/Default.aspx</link>
                  </item>
                  <item>
                  <title>XTPNR9 : 56.0000</title>
                  <description>56 .0000</description>
                  <link>http://192.168.0.131/fusionchart/Default.aspx</link>
                  </item>
                  <item>
                  <title>XTPNR2 : 78.0000</title>
                  <description>78 .0000</description>
                  <link>http://192.168.0.131/fusionchart/Default.aspx</link>
                  </item>
                  <item>
                  <title>XTPNR3 : 28.0000</title>
                  <description>28 .0000</description>
                  <link>http://192.168.0.131/fusionchart/Default.aspx</link>
                  </item>
                  <item>
                  <title>XTPNR4 : 78.0000</title>
                  <description>78 .0000</description>
                  <link>http://192.168.0.131/fusionchart/Default.aspx</link>
                  </item>
                  <item>
                  <title>XTPNR5 : 66.0000</title>
                  <description>66 .0000</description>
                  <link>http://192.168.0.131/fusionchart/Default.aspx</link>
                  </item>
                  <item>
                  <title>XTPNR6 : 98.0000</title>
                  <description>98 .0000</description>
                  <link>http://192.168.0.131/fusionchart/Default.aspx</link>
                  </item>
                  <item>
                  <title>XXABK3 : 87.0000</title>
                  <description>87 .0000</description>
                  <link>http://192.168.0.131/fusionchart/Default.aspx</link>
                  </item>
                  <item>
                  <title>XXABK7 : 56.0000</title>
                  <description>56 .0000</description>
                  <link>http://192.168.0.131/fusionchart/Default.aspx</link>
                  </item>
                  <item>
                  <title>XXABK8 : 567.0000</title>
                  <description>56 7.0000</description>
                  <link>http://192.168.0.131/fusionchart/Default.aspx</link>
                  </item>
                  <item>
                  <title>XXABK9 : 455.0000</title>
                  <description>45 5.0000</description>
                  <link>http://192.168.0.131/fusionchart/Default.aspx</link>
                  </item>
                  </channel>
                  </rss>

                  xsl code

                  <?xml version="1.0" encoding="utf-8"?>

                  <xsl:styleshe et xmlns:xsl="http ://www.w3.org/1999/XSL/Transform" version="1.0">

                  <xsl:output method="xml" indent="yes" />

                  <xsl:template match="/">

                  <channel>
                  <title>


                  <xsl:copy select="title">

                  </xsl:copy>

                  </title>

                  <xsl:apply-templates select="item"/>


                  </root>

                  </xsl:template>


                  <xsl:template match="item">

                  <xsl:for-each select="title">

                  <title>
                  <xsl:copy select="title"/>

                  </title>

                  </xsl:for-each>

                  <xsl:for-each select="descrip tion">

                  <description>
                  <xsl:copy select="descrip tion"/>

                  </description>

                  </xsl:for-each>


                  </xsl:template>


                  </xsl:stylesheet>


                  output reqiured

                  <channel>



                  <title>wholesal e</title>

                  <description>Th e latest whole sale report</description>






                  <item>


                  <title>XTPNR </title>

                  <description>12 2.0000</description>

                  </item>


                  <item>

                  <title>XTPNR0 </title>

                  <description>10 11.0000</description>

                  </item>


                  <item>

                  <title>XTPNR1 </title>

                  <description>85 .0000</description>

                  </item>


                  <item>

                  <title>XTPNR1 </title>

                  <description>85 .0000</description>

                  </item>


                  <item>

                  <title>XXABK5 </title>

                  <description>45 .0000</description>


                  </item>


                  <item>

                  <title>XXABK6 </title>

                  <description>86 .0000</description>

                  </item>


                  <item>


                  <title>XXABK2 </title>

                  <description>5. 0000</description>


                  </item>

                  <item>


                  <title>XXABK2 0 </title>

                  <description>56 .0000</description>


                  </item>

                  <item>


                  <title>XXABK4 </title>

                  <description>56 .0000</description>


                  </item>


                  <item>

                  <title>XTPNR7 </title>

                  <description>78 .0000</description>

                  </item>

                  <item>





                  <title>XTPNR8 </title>

                  <description>3. 0000</description>


                  </item>


                  <item>

                  <title>XTPNR9 </title>

                  <description>56 .0000</description>

                  </item>


                  <item>

                  <title>XTPNR2 </title>

                  <description>78 .0000</description>

                  </item>

                  <item>


                  <title>XTPNR3 </title>

                  <description> 28.0000</description>

                  </item>


                  <item>

                  <title>XTPNR4 </title>

                  <description> 78.0000</description>

                  </item>



                  <item>

                  <title>XTPNR5 </title>

                  <description> 66.0000</description>

                  </item>




                  <item>

                  <title>XTPNR6 </title>

                  <description> 98.0000</description>

                  </item>


                  <item>

                  <title>XXABK3 </title>

                  <description> 87.0000</description>

                  </item>


                  <item>

                  <title>XXABK7 </title>

                  <description>56 .0000</description>

                  </item>


                  <item>

                  <title>XXABK8 </title>

                  <description>56 7.0000</description>

                  </item>


                  <item>

                  <title>XXABK9 </title>

                  <description>45 5.0000</description>

                  </item>



                  </channel>

                  Comment

                  Working...