千里独行

国虽大,黩武必亡;天下虽安,忘战必危★★ 准备并期待着中日决战||本站文章可以全部转载

博客园 首页 新随笔 联系 订阅 管理

下载地址:https://files.cnblogs.com/yyf9989/FormatHTML.rar
格式化HTML 编制 南京袁永福 2005 yyf9989@hotmail.com
本程序用于将一个比较杂乱的HTML转换为XML或XSL代码,支持的命令行参数为:
source=要处理的HTML文件名
desc=保存处理结果的文件名
alert=0/1           是否显示提示及错误信息
xsl=0/1             是否输出为XSLT代码
scriptdata=0/1      对HTML中的Script代码是否保存在CData块中
writewhitespace=0/1 是否输出空白字符
addspan=0/1         是否在纯文本外添加span标签
normalize=0/1       是否压缩空白字符
comment=0/1         是否输出注释
formatstyle=0/1     是否格式化 Style 标签的内容
indent=0/1          输出的代码是否进行缩进格式化
help=0/1            显示本帮助消息框
gui=0/1             是否显示主用户界面,若显示主用户界面则其他参数无效
innerwritewhendisable=0/1 当某些HTML标签不进行输出时是否输出其内容和子节点

以上命令行参数名全部为小写
此外还支持如下命令行参数
span=on/off         是否输出 span 标签
font=on/off         是否输出 font 标签
类似的其他HTML标签名=on/off 是否输出指定的HTML标签
这种参数不区分大小写

例如 FormatHTML source=c:/a.htm desc=d:/a.xsl xsl=1 indent=1 font=off
则生成一个XSL文件,带缩进排版,并去除所有的 font 标签

目前支持的HTML标签有 hta:application,map,area,form,a,i,marquee,xml,sup,
   sub,input,span,div,img,table,tr,td,col,hr,font,h,h1,h2,h3,h4,h5,h6,
   textarea,select,option,html,head,body,link,pre,b,br,p,script,meta,
   bgsound,applet,param,object,ul,li,tbody,frameset,frame,iframe,label,
   ie:devicerect ,ie:layoutrect,ie:headerfooter,ie:templateprinter
目前支持XSL输出的标签为
   input(type=text , hidden , radio , checkbox)
   select,textarea, tr, td
一个生成XSL代码的例子,其原始HTML代码为
<html>
    <head>
    </head>
    <body>
        <form name=frmData>
            <input type=text name=myInput >
            <input type=checkbox name=myCheck value=abc >
            <textarea name=myTextArea>aaaa</textarea>
            <select name=mySelect xslsource=record valuexslsource=数据名 textxslsource=显示名称 >
                <option>aaaa</option>
            </select>
            <table>
                <tr xslsource=单位列表[@name='指定的单位名称']>
                    <td xslsource=产品列表>&nbsp;
                        名称:[名称]
                        数量:[数量]
                        合格率:[%:合格率]%
                        其他信息:[call:showinfo]
                   </td>
                </tr>
            </table>
        </form>
    </body>
</html>

输出的XSL代码为

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:template match="/*">
        <html>
            <head> </head>
            <body>
                <form name="frmData">
                    <input type="text" name="myInput">
                        <xsl:attribute name="value">
                            <xsl:value-of select="myInput" />
                        </xsl:attribute>
                    </input>
                    <input type="checkbox" name="myCheck" value="abc">
                        <xsl:if test="myCheck='abc'">
                            <xsl:attribute name="checked">1</xsl:attribute>
                        </xsl:if>
                    </input>
                    <textarea name="myTextArea">
                        <xsl:value-of xsl:value-of="myTextArea" />
                    </textarea>
                    <select name="mySelect" xslsource="record" valuexslsource="数据名" textxslsource="显示名称">
                        <xsl:variable name="selectvalue">
                            <xsl:value-of select="mySelect" />
                        </xsl:variable>
                        <xsl:for-each select="record">
                            <option>
                                <xsl:attribute name="value">
                                    <xsl:value-of select="数据名" />
                                </xsl:attribute>
                                <xsl:if test="$selectvalue=数据名">
                                    <xsl:attribute name="selected">1</xsl:attribute>
                                </xsl:if>
                                <xsl:value-of select="显示名称" />
                            </option>
                        </xsl:for-each>
                    </select>
                    <table>
                        <xsl:for-each select="单位列表[@name='指定的单位名称']">
                            <tr xslsource="单位列表[@name='指定的单位名称']">
                                <xsl:for-each select="产品列表">
                                    <td xslsource="产品列表">
                                        <xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text>
                        名称:<xsl:value-of select="名称" />
                        数量:<xsl:value-of select="数量" />
                        合格率:<xsl:value-of select="format-number(合格率 , '0.00')" />%
                        其他信息:<xsl:call-template name="showinfo" /></td>
                                </xsl:for-each>
                            </tr>
                        </xsl:for-each>
                    </table>
                </form>
            </body>
        </html>
    </xsl:template>
</xsl:stylesheet>

posted on 2005-12-10 12:56  千里独行  阅读(1258)  评论(0)    收藏  举报