最后,示例 3 中提供的代码基于显示格式确定执行转换。
代码示例 3. 转换页面显示
//load the Xml doc
XmlDocument myXmlDoc = new XmlDocument();
myXmlDoc.Load(sXmlPath);
//load the Xsl doc
XslTransform myXslTrans = new XslTransform();
myXslTrans.Load(sXslPath);
//do the actual transform of Xml
myXslTrans.Transform(myXmlDoc,args, Response.OutputStream);
}
catch(Exception e)
{
string msgError = "Exception: ";
Response.Write(msgError + e.Message);
}
}
static string version = "";
</script>
显示结果
本节包括来自一个 XML 源文档的示例、两个执行两个转换的 XSLT,以及两组结果(一个是富内容版本,另一个是纯文本版本)。
代码示例 4. 源 XML
<table border="5" cellpadding="5" cellspacing="5" bordercolor="#ffffff"
bgcolor="#ff9900" width="75">
<tr>
<td width="70">
<img border="0" src="/enable/images/photos/man.jpg"
width="70" height="70" alt="Man with laptop"/>
</td>
</tr>
<tr>
<td width="70">
<img src="images/photos/hand.jpg" width="70" height="70"
border="0" alt="Hand on keyboard"/>
</td>
</tr>
<tr>
<td width="70" align="middle">
<img src="images/photos/braille_fingers.gif" width="65"
height="91" valign="absmiddle" alt="Fingers feeling Braille text"
border="0"/>
</td>
</tr>
</table>
bgcolor="#ff9900" width="75">
<tr>
<td width="70">
<img border="0" src="/enable/images/photos/man.jpg"
width="70" height="70" alt="Man with laptop"/>
</td>
</tr>
<tr>
<td width="70">
<img src="images/photos/hand.jpg" width="70" height="70"
border="0" alt="Hand on keyboard"/>
</td>
</tr>
<tr>
<td width="70" align="middle">
<img src="images/photos/braille_fingers.gif" width="65"
height="91" valign="absmiddle" alt="Fingers feeling Braille text"
border="0"/>
</td>
</tr>
</table>
