LUALoriotPro WEB site

LoriotPro scripting documentation
Extensions for LUA language

Table of contents Search function

Print the current page Mail this  link UTUBE Channel version française

lp.XSLT

LoriotPro has extended the LUA sripting language by providing its own LUA libraries. The new functions provided are dedicated to the creation of monitoring and SNMP automation application.

Syntax

val= lp.XSLT('xml',xslt',html')

Description

Conversion of an XML and XSL file pair into an HTML file.

Parameters

xml - an XML file

xslt - an XML StyleSheet

Return Values

val : 1 if succeeded

html : the html file result of the XML and XSL

Return nil if an error occurs

Example

XML input file

<?xml version="1.0"?>
<?xml:stylesheet type="text/xsl" href="stock.xsl"?>
<portfolio xmlns:dt="urn:schemas-microsoft-com:datatypes">
<stock exchange="nasdaq">
<name>new</name>
<symbol>zzzz</symbol>
<price dt:dt="number">20.313</price>
</stock>
<stock exchange="nyse">
<name>zacx corp</name>
<symbol>ZCXM</symbol>
<price dt:dt="number">28.875</price>
</stock>
<stock exchange="nasdaq">
<name>zaffymat inc</name>
<symbol>ZFFX</symbol>
<price dt:dt="number">92.250</price>
</stock>
<stock exchange="nasdaq">
<name>zysmergy inc</name>
<symbol>ZYSZ</symbol>
<price dt:dt="number">20.313</price>
</stock>
</portfolio>

XSL input file

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="/">
<HTML>
<BODY>
<TABLE BORDER="2">
<TR>
<TD>Symbol</TD>
<TD>Name</TD>
<TD>Price</TD>
</TR>
<!-- Use xsl:apply-templates. -->
<xsl:apply-templates select="portfolio/stock">
<!-- Sort by stock symbols. -->
<xsl:sort select="symbol"/>
</xsl:apply-templates>
</TABLE>
</BODY>
</HTML>
</xsl:template> <xsl:template match="portfolio/stock">
<TR>
<!-- Use xsl:choose and xsl:when. -->
<xsl:attribute name="STYLE">
color:
<xsl:choose>
<xsl:when test="price[. &lt; 30]">green</xsl:when>
<xsl:when test="price[. &gt; 50]">red</xsl:when>
</xsl:choose>
</xsl:attribute>
<!-- Generate an attribute as a tooltip of TR. -->
<xsl:attribute name="Title">
<xsl:value-of select="symbol"/> is listed on the <xsl:value-of select="@exchange"/> stock exchange.
</xsl:attribute>
<TD>
<xsl:value-of select="symbol"/>
<!-- Use xsl:if. -->
<xsl:if test="@exchange[.='nasdaq']">*</xsl:if>
</TD>
<TD>
<xsl:value-of select="name"/>
</TD>
<TD>
<xsl:value-of select="price"/>
</TD>
</TR>
</xsl:template>
</xsl:stylesheet>

LUA Code

lp_value = 0;
lp_buffer ="error";
path=lp.GetPath().."/config/script/sample/"
path="c:/"
inxml=path.."stocks.xml"
inxsl=path.."stocks.xsl"
outhtm=path.."stocks.htm"
r=lp.XSLT(inxml,inxsl,outhtm);
lp.Print("result : ",r,"\n");
if r then
fp=lp.Fopen(outhtm,"rt");
if fp then
while 1 do
line=lp.Fgets(fp);
if line==nil then break end
lp.Print(line);
end
lp.Fclose(fp);
end
end

Returned file

<HTML>
<BODY>
<TABLE BORDER="2">
<TR>
<TD>Symbol</TD>
<TD>Name</TD>
<TD>Price</TD>
</TR>
<TR STYLE="&#xA; color:&#xA; green" Title="ZCXM is listed on the nyse stock exchange.&#xA; ">
<TD>ZCXM</TD>
<TD>zacx corp</TD>
<TD>28.875</TD>
</TR>
<TR STYLE="&#xA; color:&#xA; red" Title="ZFFX is listed on the nasdaq stock exchange.&#xA; ">
<TD>ZFFX*</TD>
<TD>zaffymat inc</TD>
<TD>92.250</TD>
</TR>
<TR STYLE="&#xA; color:&#xA; green" Title="ZYSZ is listed on the nasdaq stock exchange.&#xA; ">
<TD>ZYSZ*</TD>
<TD>zysmergy inc</TD>
<TD>20.313</TD>
</TR>
<TR STYLE="&#xA; color:&#xA; green" Title="zzzz is listed on the nasdaq stock exchange.&#xA; ">
<TD>zzzz*</TD>
<TD>new</TD>
<TD>20.313</TD>
</TR>
</TABLE>
</BODY>
</HTML>



www.loriotpro.com