使用xslt将xml转换为html [英] xml to html using xslt

查看:74
本文介绍了使用xslt将xml转换为html的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我需要使用xslt将一个xml文件转换为html文件的帮助.请帮助我编写xslt
xml是
=======================================

Hi,
I need help in converting one xml file to a html file using xslt.Please help me in writing the xslt
The xml is
==========================================

<assessmentItem identifier="">
  <itemBody>
    <div id="text_item_1"><![CDATA[<TEXTFORMAT LEADING="2"><P ALIGN="CENTER"><FONT FACE="HMAvenir" SIZE="20" COLOR="#000000" LETTERSPACING="0" KERNING="0"><B>Assessment</B></FONT></P></TEXTFORMAT>]]></div>
    <div id="globalInfo_item_25"><![CDATA[]]></div>
    <div id="ScoreComp_item_26"><![CDATA[<TEXTFORMAT LEADING="2"><P ALIGN="LEFT"><FONT FACE="HMAvenir" SIZE="20" COLOR="#000000" LETTERSPACING="0" KERNING="0"><B>100</B></FONT></P></TEXTFORMAT>]]></div>
    <div id="UserResponseComp_item_27"><![CDATA[<TEXTFORMAT LEADING="2"><P ALIGN="LEFT"><FONT FACE="HMAvenir" SIZE="20" COLOR="#000000" LETTERSPACING="0" KERNING="0"><B>100</B></FONT></P></TEXTFORMAT>]]></div>
    <div id="printBtn"/>
    <div id="text_item_28"><![CDATA[<TEXTFORMAT LEADING="2"><P ALIGN="CENTER"><FONT FACE="HMAvenir" SIZE="25" COLOR="#000000" LETTERSPACING="0" KERNING="1"><B>Assessment Result</B><FONT KERNING="0"></FONT></FONT></P></TEXTFORMAT>]]></div>
    <div id="text_item_29"><![CDATA[<TEXTFORMAT LEADING="2"><P ALIGN="CENTER"><FONT FACE="HMAvenir" SIZE="25" COLOR="#000000" LETTERSPACING="0" KERNING="1"><B><I>Animal Eyes</I></B></FONT></P></TEXTFORMAT>]]></div>
  </itemBody>
</assessmentItem>



====================================== <= > html(所需的输出是)
====================================== <= >



===============================================
The html(the desired output is)
===============================================

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
        <title>MCQ Score Board</title>
    </head>
    <body>
        <div id="mainContent" type="screencontent">
            <div class = "textStyle" style="position:absolute;top:170px;width:80%"><B><I>Animal Eyes</I></B></div>
            <div class = "textStyle" style="position:absolute;top:210px;left:350px;"><B>Assessment Result</B></div>
            <table style="position:absolute;top:250px;left:350px;">
                <tr>
                    <td>
                        <div data-role="globalInfoComp" id="globalInfoComp" type="globalInfoComp"  data-options='{"behaviour":"display", "infoType":"name"}'>
                            <operator name="globalInfoOperator" value="globalInfoOperator">
                            </operator>
                        </div>
                    </td>
                </tr>
                <tr>
                    <td>
                        <div data-role="UserResponseComp" id="UserResponseComp" type="UserResponseComp"  data-options='{"updateAtInitialize":true, "updateAtEvaluate":false}'>
                            <operator name="UserResponseOperator" value="UserResponseOperator">
                            </operator>
                        </div>
                    </td>
                </tr>
                <tr>
                    <td>
                        <div data-role="ScoreComp" id="ScoreComp" type="ScoreComp"  data-options='{"type":"ActivityScoreComp", "updateAtInitialize":true, "updateAtEvaluate":false}'>
                            <operator name="BaseScoreIndicatorOperator" value="BaseScoreIndicatorOperator">
                            </operator>
                        </div>
                    </td>
                </tr>
            </table>
        </div>
    </body>
</html>




==============================================


我编写的XSLT代码是
================================================== ==========




================================================


The XSLT code which I writing is
============================================================

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

    xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs" version="2.0">

    <xsl:output method="html">
    </xsl:output>
        <xsl:template match="/" >
            <xsl:for-each select="assessmentItem/itemBody/div">
                 <div>
                  <xsl:value-of select="substring-before(substring-after(.,'&lt;B&gt;'),'&lt;/B&gt;')"></xsl:value-of>
                </div>
        </xsl:for-each>
    </xsl:template>

</xsl:stylesheet>




================================================== ==========

Ayy的帮助将受到高度赞赏

提前谢谢.

问候,
Sanjeev




============================================================

Ayy help will be highly appreciated

Thanks in advance.

Regards,
Sanjeev

推荐答案

在以下链接中找到解决方案:
在运行时将XSLT样式表应用于XML文件 [ ^ ]
Find the solution in the following link:
Applying XSLT Stylesheet to an XML File at Runtime[^]


这篇关于使用xslt将xml转换为html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆