469,265 Members | 1,994 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,265 developers. It's quick & easy.

how to display xslt output in web browser

16
here is the xml code

Expand|Select|Wrap|Line Numbers
  1. <?xml-stylesheet href="example2.xsl" type="text/xsl" ?>
  2.  
  3. <?xml version="1.0" ?>
  4.  
  5. <persons>
  6.   <person username="JS1">
  7.     <name>John</name>
  8.     <family-name>Smith</family-name>
  9.   </person>
  10.   <person username="MI1">
  11.     <name>Morka</name>
  12.     <family-name>Ismincius</family-name>
  13.   </person>
  14. </persons>
xsl code

Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  3.   <xsl:output method="xml" indent="yes"/> 
  4.  
  5.   <xsl:template match="/persons">
  6.     <root>
  7.       <xsl:apply-templates select="person"/> 
  8.     </root>
  9.   </xsl:template>
  10.  
  11.   <xsl:template match="person">
  12.     <name username="{@username}">
  13.       <xsl:value-of select="name" />
  14.     </name>
  15.   </xsl:template>
  16.  
  17. </xsl:stylesheet>

output required


Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <root>
  3.   <name username="JS1">John</name>
  4.   <name username="MI1">Morka</name>
  5. </root>
Feb 13 '10 #1
8 6118
Dormilich
8,651 Expert Mod 8TB
what’s the problem? as far as my browser tells me, the output is the desired one.
Feb 13 '10 #2
sisu
16
only text is displayed in my browser no xml tags as mentioned in output field

that is 'JohnMorka'
Feb 13 '10 #3
Dormilich
8,651 Expert Mod 8TB
did you have a look at the generated* source code?

PS. you use Internet Explorer?

* - may require plugins/add-ons/extensions
Feb 13 '10 #4
drhowarddrfine
7,435 Expert 4TB
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.
Feb 13 '10 #5
sisu
16
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
Feb 14 '10 #6
Dormilich
8,651 Expert Mod 8TB
it’s exactly how doc said, a browser normally doesn’t show the tags (even if they are there).
Feb 14 '10 #7
sisu
16
i am greatfull for your kind information

thank you
Feb 14 '10 #8
sisu
16
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.xsl" type="text/xsl"?>

<rss version="2.0">

<channel>

<title>wholesale</title>

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

<description>The latest whole sale report</description>

<copyright>Copyright 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>wholesale</title>
<link>http://localhost/fusionchart/rssfeed12.aspx</link>
<description>This shows up in title of link</description>
<item>
<title>XTPNR : 122.0000</title>
<description>122.0000</description>
<link>http://192.168.0.131/fusionchart/Default.aspx</link>
</item>
<item>
<title>XTPR0 : 1011.0000</title>
<description>1011.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>XXABK20 : 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>567.0000</description>
<link>http://192.168.0.131/fusionchart/Default.aspx</link>
</item>
<item>
<title>XXABK9 : 455.0000</title>
<description>455.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:stylesheet 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="description">

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

</description>

</xsl:for-each>


</xsl:template>


</xsl:stylesheet>


output reqiured

<channel>



<title>wholesale</title>

<description>The latest whole sale report</description>






<item>


<title>XTPNR </title>

<description>122.0000</description>

</item>


<item>

<title>XTPNR0 </title>

<description>1011.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>XXABK20 </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>567.0000</description>

</item>


<item>

<title>XXABK9</title>

<description>455.0000</description>

</item>



</channel>
Feb 14 '10 #9

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Jesper Moth | last post: by
2 posts views Thread by Lionel Fourquaux | last post: by
7 posts views Thread by mjarends | last post: by
18 posts views Thread by Terry Holland | last post: by
2 posts views Thread by trash.muell | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.