Trying To Improve Structure of xml with embedded x

2019-08-27 18:24发布

问题:

I need to provide an option to generate my SQL report result data in a form that can be easily viewed by most web browsers.

RE: Why is my XSL file no longer being applied to my XML file?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> &#160; &#160; <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>

This works in Firefox 68, but is it reasonably well structured? Before I modify my program code to generate the SQL report data files in a similar fashion.

In the above example, does this part seem "well formed"?

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

<!DOCTYPE dataroot [ <!ATTLIST xsl:stylesheet  id ID #REQUIRED>]>
<?xml-stylesheet type="text/xml" href="#stylesheet"?>

Also, does this part seem "well formed"?

<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">

I have used this format to imbed xslt style code in two additional .xml query report files. Does this approach seem worth programming into my applications or are there some suggested improvements from people who really know what they are doing?

After reading some entries on the web, I made some changes: I moved

<?xml-stylesheet type="text/xsl" href="#stylesheet"?>

before DOCTYPE with changes: xml-stylesheet type was also changed to "text/xsl" as a step towards compatibility with IE 8.

Insert after xsl-stylesheet:

<xsl:template match="xsl:stylesheet" />

I do not know if these changes significantly improve the structure, or if the comments in the previous question pertained to the formatting of the xsl style coding itself?

回答1:

I have accepted on my own answer / resolution:

Why Embedded Style Code:

For years, I have been building SQL (Structured Query Language) queries and saving the results in XML (Extensible Markup Language) files.

XML is a data format that is an extension of the familiar HTML files that are viewed on web browsers. XML files carry organized data that is not pretty to look at and hard to read.

This is why we have XSL (Extensible Stylesheet Language) and XSLT (XSL Transformation).

For many years a typical XML data file would reference a companion XSL stylesheet file. This is the approach I have used and depended on in the several programs I have created.

Surprise, recently an update to Firefox (68) did not feel it was safe to look for and use this companion XSL stylesheet file. There is a short term fix to turn off this protection and carry on with the XML - XSL pair.

Some browsers (e.g.: Internet Explorer) prefer to continue with the old, external stylesheet, way.

The new way is to embed the XSLT style code within the XML data file.

The symptoms:

  • rejection of the old way (XML - XSL pair):

    browser cannot find file.XSL stylesheet. (Newer Firefox, ...)

  • rejection the new way (embed the XSLT style code):

    browser displays data all mashed together. (Internet Explorer, ...)

I have begun modifying my programs to offer the choice of embedding the style code in with the data or not.

Thank You.



标签: xml xslt