How to create a modal popup from XSL

I am creating an XSL page where I want to bring up a modal popup. The following is part of my XSL file:

   <xsl:if test="(/ShoppingBag/Multibuy/Discount) &gt; 0">
       <tr>
         <td class="sbTotalsColLeft saving">
           DiscountDetails
         </td>
         <td class="sbTotalsColRight">
       </td>
     </tr>
   </xsl:if>

What I want to do, when the client clicked on DiscountDetails, I want to display a modal popup with the information below.

   <table class="tbpromotionTypes">
     <xsl:for-each select="/ShoppingBag/MultibuyDiscountedPromotionTypes/PromotionType">
       <tr>
         <td class="ptLeft ">
           <xsl:value-of select ="./PromotionHeading"/>
         </td>
         <td class="ptRight">
           <xsl:value-of select="./DiscountedPrice"/>
         </td>
       </tr>
     </xsl:for-each>
   </table>
+1
source share
2 answers

XSLT has no idea about pop-ups or clicks.

You can use xsl:messsageto write text to the console.

You can convert XML to HTML, including JavaScript, if necessary, to create a page in which modal dialog boxes and clicks are functional concepts.

For this input sample file:

<?xml version="1.0" encoding="UTF-8"?>
<ShoppingBag>
  <MultibuyDiscountedPromotionTypes>
    <PromotionType>
      <PromotionHeading>Bread</PromotionHeading>
      <DiscountedPrice>$1</DiscountedPrice>
    </PromotionType>
    <PromotionType>
      <PromotionHeading>Eggs</PromotionHeading>
      <DiscountedPrice>$2</DiscountedPrice>
    </PromotionType>
    <PromotionType>
      <PromotionHeading>Milk</PromotionHeading>
      <DiscountedPrice>$2</DiscountedPrice>
    </PromotionType>
  </MultibuyDiscountedPromotionTypes>
</ShoppingBag>

This XSLT script:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="html" indent="yes"/>
  <xsl:template match="/">
    <html lang="en">
      <head>
        <meta charset="utf-8" />
        <title>jQuery UI Dialog - Default functionality</title>
        <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
        <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
        <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
        <link rel="stylesheet" href="/resources/demos/style.css" />
        <script>
          $(function() {
            $( "#dialog" ).dialog({autoopen: false});
            $( "#dialog" ).dialog("close");
          });
          $(document).ready(function() {
            $('#discountDetailsId').click(function() {
              $( "#dialog" ).dialog({ modal: true });
            });
          });
        </script>
      </head>
      <body>
        <table>
          <tr>
            <td id="discountDetailsId">DiscountDetails</td>
          </tr>
        </table>
        <div id="dialog" title="Discount Details">
          <table class="tbpromotionTypes">
            <xsl:for-each select="/ShoppingBag/MultibuyDiscountedPromotionTypes/PromotionType">
              <tr>
                <td class="ptLeft ">
                  <xsl:value-of select ="./PromotionHeading"/>
                </td>
                <td class="ptRight">
                  <xsl:value-of select="./DiscountedPrice"/>
                </td>
              </tr>
            </xsl:for-each>
          </table>
        </div>
      </body>
    </html>
  </xsl:template>
</xsl:stylesheet>

HTML (jsfiddle.net):

<html lang="en">
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <meta charset="utf-8">
      <title>jQuery UI Dialog - Default functionality</title>
      <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css"><script src="http://code.jquery.com/jquery-1.9.1.js"></script><script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script><link rel="stylesheet" href="/resources/demos/style.css"><script>
          $(function() {
            $( "#dialog" ).dialog({autoopen: false});
            $( "#dialog" ).dialog("close");
          });
          $(document).ready(function() {
            $('#discountDetailsId').click(function() {
              $( "#dialog" ).dialog({ modal: true });
            });
          });
        </script></head>
   <body>
      <table>
         <tr>
            <td id="discountDetailsId">DiscountDetails</td>
         </tr>
      </table>
      <div id="dialog" title="Discount Details">
         <table class="tbpromotionTypes">
            <tr>
               <td class="ptLeft ">Bread</td>
               <td class="ptRight">$1</td>
            </tr>
            <tr>
               <td class="ptLeft ">Eggs</td>
               <td class="ptRight">$2</td>
            </tr>
            <tr>
               <td class="ptLeft ">Milk</td>
               <td class="ptRight">$2</td>
            </tr>
         </table>
      </div>
   </body>
</html>

, DiscountDetails .

enter image description here

0

: td "sbTotalsColLeft" "" JQuery

$(".sbTotalsColLeft").Click(...... modal popup code here ....);

: http://jqueryui.com/dialog/

-1

Source: https://habr.com/ru/post/1622257/


All Articles