0
votes

Most web browsers (except Internet Explorer) are requiring that the stylesheet code be embedded in with the xml data.

In most cases I have been successful in generating xml files dealing with either situation, by providing a configuration switch in my VB6 programs. I have been able to use <xsl:apply-templates .../>

Usually, I can copy almost all of the stylesheet code from its .xsl or .xslt file and insert near the top of the .xml data file and make a few adjustments to generate the report with its embedded style code.

The BIG exception is when the external .xsl file stylesheet code uses <xsl:call-template .../>

This external stylesheet creates a nice 4 column list, ordered down the 1st, 2nd, 3rd and then 4th columns. The first 3 columns are the same length with the 4th completing the list .

All my attempts to embed this stylesheet result in everything crammed in across the top.

In the reference books and on line, I see a number of examples for formatting this in external stylesheet. I probably plagiarized one of these examples years ago.

Has <xsl:call-template .../> been successfully used in embedded stylesheets?

If so, how?, please!

My VB6 programs use databases and I generate reports as .xml files to be displayed in web browsers.


DATA CSellerList.xml:

<?xml version='1.0' encoding='UTF-8'?>
<?xml-stylesheet type='text/xsl' href='.\CSellerList.xsl'?>
<dataroot maintitle='Ticket Manager : SOUPe313.mdb' generated='2020-06-29T06:28:28'>
  <NameFL>Clark Carlton</NameFL>
  <NameFL>Diana Axel</NameFL>
  <NameFL>Susie Brown</NameFL>
  <NameFL>unknown buyer</NameFL>
  <NameFL>Russ Roberts</NameFL>
  <NameFL>Donna Davis</NameFL>
  <NameFL>Dori Diller</NameFL>
  <NameFL>Niola Norse</NameFL>
  <NameFL>At The Door</NameFL>
  <NameFL>Organization FinSecy</NameFL>
  <NameFL>Joe James</NameFL>
  <NameFL>Fern Friendly</NameFL>
  <NameFL>Madelyn Morse</NameFL>
  <NameFL>Joe James</NameFL>
  <NameFL>Alice Avery</NameFL>
  <NameFL>Connie Carson</NameFL>
  <NameFL>John Knife</NameFL>
  <NameFL>Matt Miller</NameFL>
  <NameFL>Bev Baker</NameFL>
  <NameFL>Financial Secretary</NameFL>
  <NameFL>Janet Johnson</NameFL>
  <NameFL>Biff Brown</NameFL>
  <NameFL>Ruth Ready</NameFL>
</dataroot>

External stylesheet CSellerList.xsl:

<xsl:stylesheet version='1.0'
  xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
  xmlns:text='http://www.ora.com/XSLTCookbook/namespaces/text'
>
  <xsl:output method='html' version='4.0' indent='yes'/>

  <xsl:template match='dataroot'>
    <html>
      <head>
        <META HTTP-EQUIV='Content-Type' CONTENT='text/html;charset=UTF-8'/>
        <title>SellerList</title>
        <style type='text/css'>
        body {
          background-color:white;
          color:black;
          font-family:arial;
          font-selection-strategy:auto;
          font-size:11pt;
          font-stretch:normal;
          font-size-adjust:none;
          font-style:normal;
          font-variant:normal;
          font-weight:normal;
        }
        </style>
     </head>
     <body>
        <h2 align='center'><xsl:value-of select='@maintitle'/> - Seller List</h2>
        <table border='0' width='100%'>
          <xsl:call-template name='text:col-major'>
            <xsl:with-param name='nodes' select='NameFL'/>
            <xsl:with-param name='num-cols' select='4'/>
          </xsl:call-template>
        </table>
      </body>
    </html>
  </xsl:template>

  <xsl:template name='text:row-major'>
    <xsl:param name='nodes' select='/..'/>
    <xsl:param name='num-cols' select='2'/>

    <xsl:if test='$nodes'>
      <tr>
        <xsl:call-template name='text:row'>
          <xsl:with-param name='nodes' select='$nodes[position() &lt;= $num-cols]'/>
        </xsl:call-template>
      </tr>
      <!-- process remaining rows -->
      <xsl:call-template name='text:row-major'>
        <xsl:with-param name='nodes' select='
          $nodes[position() &gt; $num-cols]
        '/>
        <xsl:with-param name='num-cols' select='$num-cols'/>
      </xsl:call-template>
    </xsl:if>
  </xsl:template>

  <xsl:template name='text:col-major'>
    <xsl:param name='nodes' select='/..'/>
    <xsl:param name='num-cols' select='2'/>

    <xsl:if test='$nodes'>
      <tr>
        <xsl:call-template name='text:row'>
          <xsl:with-param name='nodes' select='
            $nodes[(position() - 1) mod ceiling(last() div $num-cols) = 0]
          '/>
        </xsl:call-template>
      </tr>
      <!-- process remaining rows -->
      <xsl:call-template name='text:col-major'>
        <xsl:with-param name='nodes'
          select='$nodes[(position() - 1) mod
          ceiling(last() div $num-cols) != 0]'/>
        <xsl:with-param name='num-cols' select='$num-cols'/>
      </xsl:call-template>
    </xsl:if>
  </xsl:template>

  <xsl:template name='text:row'>
    <xsl:param name='nodes' select='/..'/>
    <xsl:for-each select='$nodes'>
      <td>
        <xsl:value-of select='node()'/>
      </td>
    </xsl:for-each>
    <xsl:text>&#xa;</xsl:text>
  </xsl:template>
</xsl:stylesheet>

This works in Internet Explorer, but not in FireFox.


The result with external stylsheet looks much like this in Internet Explorer:

            Ticket Manager : SOUPe313.mdb - Seller List

Clark Carlton   Dori Diller             Madelyn Morse    Bev Baker 
Diana Axel      Niola Norse             Joe James        Financial Secretary 
Susie Brown     At The Door             Alice Avery      Janet Johnson 
unknown buyer   Organization FinSecy    Connie Carson    Biff Brown 
Russ Roberts    Joe James               John Knife       Ruth Ready 
Donna Davis     Fern Friendly           Matt Miller 

and like this (garbled) on Firefox:

Clark Carlton Diana Axel Susie Brown unknown buyer Russ Roberts Donna Davis Dori Diller Niola 
Norse At The Door Organization FinSecy Joe James Fern Friendly Madelyn Morse Joe James Alice 
Avery Connie Carson John Knife Matt Miller Bev Baker Financial Secretary Janet Johnson Biff Brown 
Ruth Ready


Embedded DSellerList.xml that reasonably works (It does not use <xsl:call-template .../>):

<?xml version='1.0' encoding='UTF-8'?>
<?xml-stylesheet type='text/xsl' href='#stylesheet'?>
<!DOCTYPE dataroot [ <!ATTLIST xsl:stylesheet  id ID #REQUIRED>]>
<dataroot maintitle='Ticket Manager : SOUPe313.mdb' generated='2020-06-29T06:27:46'>
<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'>

   <html>
       <head>
           <META HTTP-EQUIV='Content-Type' CONTENT='text/html;charset=UTF-8'/>
            <title>SellerList</title>
           <style type='text/css'>
               body
               {
              background-color:white;
              color:black;
              font-family:arial;
              font-selection-strategy:auto;
              font-size:11pt;
              font-stretch:normal;
              font-size-adjust:none;
              font-style:normal;
              font-variant:normal;
              font-weight:normal;
               }
           </style>
       </head>
       <body>
         <h2 align='center'><xsl:value-of select='@maintitle'/> - Seller List</h2>
                <table border='0' cellpadding='0' align='center'>
                <thead>
                <tr>
                <th>Seller Name - First Last</th>
                </tr>
                </thead>
                <tbody>
                <xsl:apply-templates select='NameFL'/>

                </tbody>
                </table>
                
           </body>
       </html>
  </xsl:template>
  <xsl:template match='NameFL' >
    <tr>    
        <td align='center'><xsl:value-of select='.'/></td>
    </tr>   
  </xsl:template>
</xsl:stylesheet>

<NameFL>Clark Carlton</NameFL>

<NameFL>Diana Axel</NameFL>

<NameFL>Susie Brown</NameFL>

<NameFL>unknown buyer</NameFL>

<NameFL>Russ Roberts</NameFL>

<NameFL>Donna Davis</NameFL>

<NameFL>Dori Diller</NameFL>

<NameFL>Niola Norse</NameFL>

<NameFL>At The Door</NameFL>

<NameFL>Organization FinSecy</NameFL>

<NameFL>Joe James</NameFL>

<NameFL>Fern Friendly</NameFL>

<NameFL>Madelyn Morse</NameFL>

<NameFL>Joe James</NameFL>

<NameFL>Alice Avery</NameFL>

<NameFL>Connie Carson</NameFL>

<NameFL>John Knife</NameFL>

<NameFL>Matt Miller</NameFL>

<NameFL>Bev Baker</NameFL>

<NameFL>Financial Secretary</NameFL>

<NameFL>Janet Johnson</NameFL>

<NameFL>Biff Brown</NameFL>

<NameFL>Ruth Ready</NameFL>

</dataroot>

The result with embedded stylesheet is much like this in Firefox and many other browsers:

      Ticket Manager : SOUPe313.mdb - Seller List

             Seller Name - First Last
                    Clark Carlton
                     Diana Axel
                     Susie Brown
                    unknown buyer
                     Russ Roberts
                     Donna Davis
                     Dori Diller
                     Niola Norse
                     At The Door
                 Organization FinSecy
                      Joe James
                    Fern Friendly
                    Madelyn Morse
                      Joe James
                     Alice Avery
                    Connie Carson
                     John Knife
                     Matt Miller
                      Bev Baker
                 Financial Secretary
                    Janet Johnson
                      Biff Brown
                      Ruth Ready

and garbled like this in Internet Explorer:

SellerList  body { background-color:white; color:black; font-family:arial; font-selection-strategy:auto; 
font-size:11pt; font-stretch:normal; font-size-adjust:none; font-style:normal; font-variant:normal; font-
weight:normal; } - Seller List Seller Name - First Last Clark Carlton Diana Axel Susie Brown unknown 
buyer Russ Roberts Donna Davis Dori Diller Niola Norse At The Door Organization FinSecy Joe James 
Fern Friendly Madelyn Morse Joe James Alice Avery Connie Carson John Knife Matt Miller Bev Baker 
Financial Secretary Janet Johnson Biff Brown Ruth Ready 


YES, Thank you very much. 3 elements near the top make the world of difference!

<xsl:stylesheet version='1.0' id="stylesheet"
    xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
    xmlns:text='http://www.ora.com/XSLTCookbook/namespaces/text'
    >
    <xsl:output method='html' version='4.0' indent='yes'/>
    
    <xsl:template match='dataroot'>

They also work in 3 other reports from the same program.

1
I don't understand what you refer to with your claim in the first sentence. Which browser documents that you need to embed XSLT in XML? Are you trying to load XML over HTTP(S) or from the file system? - Martin Honnen
It would also helped if you showed minimal but complete sample of XML, XSLT and output you get versus the one you want. - Martin Honnen
I would suggest, as an experiment to eliminate one possible line of investigation, trying xsl:call-template on a template name that is NOT in a namespace. (Conjecture: perhaps with embedded stylesheets the namespace declaration is being handled incorrectly.) - Michael Kay
Please also show the sample that you have with embedded XSLT that fails to produce the wanted output. Perhaps it is only a namespace problem. - Martin Honnen

1 Answers

0
votes

The following "embedded" XSLT works fine in Chrome and Firefox when the XML containing it is loaded:

<?xml version='1.0' encoding='UTF-8'?>
<?xml-stylesheet type='text/xsl' href='#stylesheet'?>
<!DOCTYPE dataroot [ <!ATTLIST xsl:stylesheet  id ID #REQUIRED>]>
<dataroot maintitle='Ticket Manager : SOUPe313.mdb' generated='2020-06-29T06:27:46'>
    <xsl:stylesheet version='1.0' id="stylesheet"
        xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
        xmlns:text='http://www.ora.com/XSLTCookbook/namespaces/text'
        >
        <xsl:output method='html' version='4.0' indent='yes'/>
        
        <xsl:template match='dataroot'>
            <html>
                <head>
                    <title>SellerList</title>
                    <style type='text/css'>
                        body {
                        background-color:white;
                        color:black;
                        font-family:arial;
                        font-selection-strategy:auto;
                        font-size:11pt;
                        font-stretch:normal;
                        font-size-adjust:none;
                        font-style:normal;
                        font-variant:normal;
                        font-weight:normal;
                        }
                    </style>
                </head>
                <body>
                    <h2 align='center'><xsl:value-of select='@maintitle'/> - Seller List</h2>
                    <table border='0' width='100%'>
                        <xsl:call-template name='text:col-major'>
                            <xsl:with-param name='nodes' select='NameFL'/>
                            <xsl:with-param name='num-cols' select='4'/>
                        </xsl:call-template>
                    </table>
                </body>
            </html>
        </xsl:template>
        
        <xsl:template name='text:row-major'>
            <xsl:param name='nodes' select='/..'/>
            <xsl:param name='num-cols' select='2'/>
            
            <xsl:if test='$nodes'>
                <tr>
                    <xsl:call-template name='text:row'>
                        <xsl:with-param name='nodes' select='$nodes[position() &lt;= $num-cols]'/>
                    </xsl:call-template>
                </tr>
                <!-- process remaining rows -->
                <xsl:call-template name='text:row-major'>
                    <xsl:with-param name='nodes' select='
                        $nodes[position() &gt; $num-cols]
                        '/>
                    <xsl:with-param name='num-cols' select='$num-cols'/>
                </xsl:call-template>
            </xsl:if>
        </xsl:template>
        
        <xsl:template name='text:col-major'>
            <xsl:param name='nodes' select='/..'/>
            <xsl:param name='num-cols' select='2'/>
            
            <xsl:if test='$nodes'>
                <tr>
                    <xsl:call-template name='text:row'>
                        <xsl:with-param name='nodes' select='
                            $nodes[(position() - 1) mod ceiling(last() div $num-cols) = 0]
                            '/>
                    </xsl:call-template>
                </tr>
                <!-- process remaining rows -->
                <xsl:call-template name='text:col-major'>
                    <xsl:with-param name='nodes'
                        select='$nodes[(position() - 1) mod
                        ceiling(last() div $num-cols) != 0]'/>
                    <xsl:with-param name='num-cols' select='$num-cols'/>
                </xsl:call-template>
            </xsl:if>
        </xsl:template>
        
        <xsl:template name='text:row'>
            <xsl:param name='nodes' select='/..'/>
            <xsl:for-each select='$nodes'>
                <td>
                    <xsl:value-of select='node()'/>
                </td>
            </xsl:for-each>
            <xsl:text>&#xa;</xsl:text>
        </xsl:template>
    </xsl:stylesheet>
    
    
    <NameFL>Clark Carlton</NameFL>
    
    <NameFL>Diana Axel</NameFL>
    
    <NameFL>Susie Brown</NameFL>
    
    <NameFL>unknown buyer</NameFL>
    
    <NameFL>Russ Roberts</NameFL>
    
    <NameFL>Donna Davis</NameFL>
    
    <NameFL>Dori Diller</NameFL>
    
    <NameFL>Niola Norse</NameFL>
    
    <NameFL>At The Door</NameFL>
    
    <NameFL>Organization FinSecy</NameFL>
    
    <NameFL>Joe James</NameFL>
    
    <NameFL>Fern Friendly</NameFL>
    
    <NameFL>Madelyn Morse</NameFL>
    
    <NameFL>Joe James</NameFL>
    
    <NameFL>Alice Avery</NameFL>
    
    <NameFL>Connie Carson</NameFL>
    
    <NameFL>John Knife</NameFL>
    
    <NameFL>Matt Miller</NameFL>
    
    <NameFL>Bev Baker</NameFL>
    
    <NameFL>Financial Secretary</NameFL>
    
    <NameFL>Janet Johnson</NameFL>
    
    <NameFL>Biff Brown</NameFL>
    
    <NameFL>Ruth Ready</NameFL>
    
</dataroot>