Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

XSL to html conversion

 
sri chitra
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 254
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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>
 
sri chitra
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot. It worked!
 
sri chitra
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 254
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try replacing htmlString template by

<xsl:template name="htmlString">
<xsl:variable name="value" select="./@value"/>
<P><xsl:value-of select="$value"/></P>
</xsl:template>
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic