XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Praneeth PVSubject: Need help to convert XMl -> HTML
Author: Praneeth PV
Date: 21 Apr 2007 08:53 AM
Hi there,
Am new to xsl. I am trying to convert an xml to html. The structure of my xml looks like this.
<lines>
<line>
<A>+</A>
<B>BLUE</B>
<C>DATA1</C>
</line>
<line>
<A>+</A>
<B>PINK</B>
<C>DATA2</C>
</line>
</lines>

I want my html output to look like this:

+DATA1
+DATA2

The color mentioned in <B> indicates the bgcolor, it is valid till the next <B> is encountered.

As mentioned earlier, am very new to xsl. I guess my XPATH expressions are not correct. My output looks like this:

+
DATA1
+
DATA2

I want all <line> elements to end with a newline, and all children in a line element should be on the same line.

Please help me out.

Thanks

Postnext
(Deleted User) Subject: Need help to convert XMl -> HTML
Author: (Deleted User)
Date: 23 Apr 2007 12:54 PM
Hi Praneeth,
you need to give us more informations:
- which version of Stylus Studio are you using?
- which XSLT processor are you using?
- is the XSLT generating TEXT or HTML?
- could you post the fragment of the XSLT that generates the result you posted?

Thanks,
Alberto

Postnext
Praneeth PVSubject: Need help to convert XMl -> HTML
Author: Praneeth PV
Date: 24 Apr 2007 09:07 AM
Hi Alberto,

Here is the information you asked for.
This is my xml.

<?xml version="1.0" encoding="UTF-8"?>
<lines>
<line>
<A>+</A>
<B>BLUE</B>
<C>DATA1</C>
</line>
<line>
<A>+</A>
<B>PINK</B>
<C>DATA2</C>
</line>
</lines>

This is the xsl I have written:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:template match="/">
<html>
<head><title>MyHTML</title></head>
<body>
<pre>
<xsl:for-each select="lines">
<xsl:for-each select="child::line">

<xsl:choose>
<xsl:when test="A">
<xsl:apply-templates select="."/>
</xsl:when>
<xsl:when test="B">
<xsl:apply-templates select="."/>
</xsl:when>
<xsl:when test="C">
<xsl:apply-templates select="."/>
</xsl:when>
</xsl:choose>
</xsl:for-each>
<br></br>
</xsl:for-each>
</pre>
</body>
</html>
</xsl:template>
<xsl:template match="A">
<xsl:value-of select="."></xsl:value-of>
</xsl:template>
<xsl:template match="C">
<xsl:value-of select="."></xsl:value-of>
</xsl:template>
</xsl:stylesheet>

Now, if you notice, I haven't defined a template to handle <B>. But my output when i used XMLSpy 2004 Enterprise Edition is:
+BLUEDATA1+PINKDATA2

When i used IntelliJ's built-in XSLT processor, the same xsl on the same xml produced this output:
+
BLUE
DATA1

+
PINK
DATA2

I am not sure how 'BLUE' and 'PINK' are seen in the html output in the first place.
Please help me. I hope I have provided all information this time.

Thanks,
Praneeth

Posttop
(Deleted User) Subject: Need help to convert XMl -> HTML
Author: (Deleted User)
Date: 24 Apr 2007 09:26 AM
Hi Praneeth,
even if you didn't define a template for B, XSLT defines a default template that prints any text node (including the text nodes that makes up the indentation of the XSLT stylesheet itself).
I would suggest you to download a trial copy of Stylus Studio and use its debugger to see how a processor generates its output.

Hope this helps,
Alberto

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.