Thread: HOw to display in XML chemichals formula


Permlink Replies: 3 - Pages: 1 - Last Post: Apr 10, 2006 12:22 AM Last Post By: user502006
user502006

Posts: 2
Registered: 04/07/06
HOw to display in XML chemichals formula
Posted: Apr 7, 2006 2:30 PM
Click to report abuse...   Click to reply to this thread Reply
Hi gurus!!
We are implementing OPM Quality module in chemical company. Customer requirements is to print chemichal formule in <<chemicals characters>> e.g not CO2 but CO and small 2

Could YOu plesase advise how thie ihis issue can be solved

Best Regards
Lucjan
Tim Dexter

Posts: 2,268
Registered: 01/10/01
Re: HOw to display in XML chemichals formula
Posted: Apr 7, 2006 8:53 PM   in response to: user502006 in response to: user502006
Click to report abuse...   Click to reply to this thread Reply
Hi Lucjan
So if I remember my college chemistry then as long as you have a chemical formula then all the numeric characters need to be subscripted.
So with a little digging on the web I found a template that can be used, thanks to Kevin for the template.
http://www.biglist.com/lists/xsl-list/archives/200210/msg01480.html

So I took the template:
<xsl:template name="chemical_formater">
<xsl:param name="formula"/>
<xsl:variable name="each_char" select="substring($formula,1,1)"/>
<xsl:choose>
<xsl:when test="$each_char='1' or $each_char='2' or $each_char='3' or
$each_char='4' or $each_char='5' or $each_char='6' or $each_char='7' or
$each_char='8' or $each_char='9' or $each_char='0'">
<fo:inline baseline-shift="sub" font-size="75%">
<xsl:value-of select="$each_char"/>
</fo:inline>
</xsl:when>
<xsl:otherwise>
<fo:inline baseline-shift="normal">
<xsl:value-of select="$each_char"/>
</fo:inline>
</xsl:otherwise>
</xsl:choose>
<xsl:if test="substring-after($formula,$each_char)!=''">
<xsl:call-template name="chemical_formater">
<xsl:with-param name="formula">
<xsl:value-of
select="substring-after($formula,$each_char)"/>
</xsl:with-param>
</xsl:call-template>
</xsl:if>
</xsl:template>
and put it in a separate XSL file, this can be loaded to the Template Manager and referenced from the main template.
Using the following XML
<ROWSET>
<ROW>
<VALUE>CO2</VALUE>
</ROW>
<ROW>
<VALUE>H2O</VALUE>
</ROW>
</ROWSET>
In the formfield where you want to show the formula:
<xsl:call-template name="chemical_formater">
<xsl:with-param name="formula" select="VALUE"/> </xsl:call-template>
This calls the chemical formatter template and passes the VALUE element for formatting. It returns the formula formatted correctly ie with the subscripts.
Regards, Tim
Tim Dexter

Posts: 2,268
Registered: 01/10/01
Re: HOw to display in XML chemichals formula
Posted: Apr 9, 2006 4:53 PM   in response to: Tim Dexter in response to: Tim Dexter
Click to report abuse...   Click to reply to this thread Reply
I have written this up more fully and provided sample code in our new XMLP Blog, http://blogs.oracle.com/xmlpublisher/
user502006

Posts: 2
Registered: 04/07/06
Re: HOw to display in XML chemichals formula
Posted: Apr 10, 2006 12:22 AM   in response to: Tim Dexter in response to: Tim Dexter
Click to report abuse...   Click to reply to this thread Reply
Hi Tim !
Thanks a lot. As always You give very good advices.

Best Regards
Lucjan
Legend
Guru Guru : 2500 - 1000000 pts
Expert Expert : 1000 - 2499 pts
Pro Pro : 500 - 999 pts
Journeyman Journeyman : 200 - 499 pts
Newbie Newbie : 0 - 199 pts
Oracle ACE Director
Oracle ACE Member
Oracle Employee ACE
Helpful Answer (5 pts)
Correct Answer (10 pts)

Point your RSS reader here for a feed of the latest messages in all forums