【发布时间】:2019-07-23 21:28:32
【问题描述】:
我需要提供一个选项,以大多数 Web 浏览器都可以轻松查看的形式生成我的 SQL 报告结果数据。
RE:为什么我的 XSL 文件不再应用于我的 XML 文件?Why is my XSL file no longer being applied to my XML file?
<?xml version='1.0' encoding='UTF-8'?>
<?xml-stylesheet type="text/xsl" href="#stylesheet"?>
<!DOCTYPE dataroot [ <!ATTLIST xsl:stylesheet id ID #REQUIRED>]>
<dataroot generated='2019-07-22T11:17:37'>
<xsl:stylesheet id="stylesheet" version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="xsl:stylesheet" />
<xsl:template match="//dataroot" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<html>
<head>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html;charset=UTF-8"/>
<title>SearchMealTimeFoodQuantityP</title>
<style type="text/css">
body
{
background-color:white;
color:black;
font-family:arial;
font-selection-strategy:auto;
font-size:9pt;
font-stretch:normal;
font-size-adjust:none;
font-style:normal;
font-variant:normal;
font-weight:normal;
}
</style>
</head>
<body link="#0000ff" vlink="#800080">
<table BORDER="1" CELLSPACING="0" width="100%">
<tr><th colspan=" 4" > <big><big><xsl:value-of select="ReportTitle"/> </big></big>     <small> <xsl:value-of select="ReportDate"/></small></th> </tr>
<tr>
<th>MealTime</th>
<th>Food</th>
<th>FoodDescription</th>
<th>Quantity</th>
</tr>
<xsl:for-each select="qrSearchMealTimeFoodQuantityP">
<tr>
<td align="center"> <xsl:value-of select="MealTime"/> </td>
<td align="center"> <xsl:value-of select="Food"/> </td>
<td align="center"> <xsl:value-of select="FoodDescription"/> </td>
<td align="center"> <xsl:value-of select="Quantity"/> </td>
</tr>
<!-- Prepare for any expressions in the group footer -->
</xsl:for-each><!-- Prepare for any expressions in the group footer -->
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
<ReportTitle>Search MealTime Food Quantity P</ReportTitle>
<ReportDate>2019-07-22 11:17:37</ReportDate>
<reportdatetime>22 Jul 2019 11:17:37</reportdatetime>
<qrSearchMealTimeFoodQuantityP>
<MealTime>5/24/2019 1:10:35 PM</MealTime>
<Food>BvgChocolateMilkshake</Food>
<FoodDescription>Chocolate Milkshake</FoodDescription>
<Quantity>Large = Venti = 20oz</Quantity>
</qrSearchMealTimeFoodQuantityP>
<qrSearchMealTimeFoodQuantityP>
<MealTime>5/19/2019 1:30:53 PM</MealTime>
<Food>BvgChocolateMilkshake</Food>
<FoodDescription>Chocolate Milkshake</FoodDescription>
<Quantity>XLarge = 24oz</Quantity>
</qrSearchMealTimeFoodQuantityP>
<qrSearchMealTimeFoodQuantityP>
<MealTime>3/24/2019 1:00:20 PM</MealTime>
<Food>BvgChocolateMilkshake</Food>
<FoodDescription>Chocolate Milkshake</FoodDescription>
<Quantity>Large = Venti = 20oz</Quantity>
</qrSearchMealTimeFoodQuantityP>
</dataroot>
这在 Firefox 68 中有效,但它的结构是否合理?在我修改我的程序代码以类似方式生成 SQL 报告数据文件之前。
在上面的例子中,这部分看起来“格式正确”吗?
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE dataroot [ <!ATTLIST xsl:stylesheet id ID #REQUIRED>]>
<?xml-stylesheet type="text/xml" href="#stylesheet"?>
另外,这部分看起来“格式正确”吗?
<xsl:stylesheet id="stylesheet" version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="//dataroot" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
我已使用这种格式将 xslt 样式代码嵌入到另外两个 .xml 查询报告文件中。 这种方法是否值得在我的应用程序中进行编程,或者是否有一些真正了解自己在做什么的人提出的改进建议?
在阅读了网上的一些条目后,我做了一些更改: 我搬家了
<?xml-stylesheet type="text/xsl" href="#stylesheet"?>
在更改 DOCTYPE 之前:xml-stylesheet 类型也更改为“text/xsl”作为与 IE 8 兼容的一步。
在 xsl 样式表之后插入:
<xsl:template match="xsl:stylesheet" />
不知道这些变化是否显着改善了结构,还是上一题中的 cmets 与 xsl 样式编码本身的格式有关?
【问题讨论】:
-
我已经看到了一些将 xslt 代码嵌入到 xml 中的不同方法。我更喜欢把它放在数据之前。我希望以我的 xslt 代码形式提供一些指导,特别是如果更改可以使其适用于更多浏览器。我有几本 XSLT 参考书,但只有一本涉及嵌入式样式表。