aspose file tools*
The moose likes XML and Related Technologies and the fly likes XSL to html conversion Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "XSL to html conversion" Watch "XSL to html conversion" New topic
Author

XSL to html conversion

sri chitra
Greenhorn

Joined: Nov 16, 2000
Posts: 22
I am trying to convert an xml into a html using XSL
THe xml is:
<?xml version="1.0"?>
<element type="text" fillvalue="abc">
</element>
In the xsl, I would like to set the attribute of a HTML tag
by reading the fillvalue value of the element tag.
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
<INPUT TYPE="text" VALUE="<xsl:value-of select="@fillvalue"/>" />
</xsl:template>
</xsl:stylesheet>
But I am getting some errors(cannot have < after "),
if I use the above syntax.
What is the proper XSL syntax?
Thanks in advance,
C.
Kripal Singh
Ranch Hand

Joined: Jul 26, 2001
Posts: 254
Try this XSL
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/element">
<xsl:variable name="VAL">
<xsl:value-of select="@fillvalue"/>
</xsl:variable>
<INPUT TYPE="text" VALUE="{$VAL}" />
</xsl:template>
</xsl:stylesheet>

# Help an unprivileged kid.<br /> Whatever u do will make a difference...<br /> ...to a child's life & ur own #<br /><a href="http://www.cry.org/" target="_blank" rel="nofollow">www.cry.org/</a>
sri chitra
Greenhorn

Joined: Nov 16, 2000
Posts: 22
Thanks a lot. It worked!
sri chitra
Greenhorn

Joined: Nov 16, 2000
Posts: 22
I used the above technique for this xsl.
It works fine except when I add the third template named
htmlString.
What is wrong with that template?
The error that I get is "oracle.xml.parser.v2.XMLDOMException: Node of this type cannot be added"
xml file:
<?xml version="1.0"?>
<tree>
<list>
<item>
<element type="string" value="abc"></element>
<element type="image" src="/images/upload.gif"></element>
<list>
<item>
<element type="string" value="def"></element>
<element type="image" src="/images/upload.gif"></element>
</item>
</list>
</item>
</list>
</tree>

XSL file:

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">

<xsl:for-each select="item/element">
<xsl:choose>
<xsl:when test="contains(@type,'text')">
<xsl:call-template name="htmlText"/>
</xsl:when>

<xsl:when test="contains(@type,'image')">
<xsl:call-template name="htmlImage"/>
</xsl:when>

<xsl:when test="contains(@type,'string')">
<xsl:call-template name="htmlString"/>
</xsl:when>

</xsl:choose>
</xsl:for-each>
</xsl:template>
<xsl:template name="htmlText">
<xsl:variable name="value" select="./@value"/>

<INPUT TYPE="text" VALUE="{$value}"/>

</xsl:template>

<xsl:template name="htmlImage">
<xsl:variable name="src" select="./@src"/>

<IMG SRC="{$src}"/>

</xsl:template>

<xsl:template name="htmlString">
<xsl:variable name="value" select="./@value"/>

<P>{$value}</P>

</xsl:template>

</xsl:stylesheet>
sri chitra
Greenhorn

Joined: Nov 16, 2000
Posts: 22
One small correction in the above question.
The xml file is:
<?xml version="1.0"?>
<item>
<element type="string" value="abc"></element>
<element type="image" src="/images/upload.gif"></element>
</item>
Kripal Singh
Ranch Hand

Joined: Jul 26, 2001
Posts: 254
try replacing htmlString template by

<xsl:template name="htmlString">
<xsl:variable name="value" select="./@value"/>
<P><xsl:value-of select="$value"/></P>
</xsl:template>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: XSL to html conversion