9

我可以在全局范围内声明一个值为“111”的变量“myVariable”。但是我怎样才能在本地重新分配一个值。或者有没有其他方法可以实现这一点。

请帮忙。谢谢你。拉维

4

2 回答 2

8

您可以在模板中重新定义相同的变量:

<xsl:variable name="myVariable" select="'111'"/>

<xsl:template match="/">
  <xsl:variable name="myVariable" select="'112'"/>
  . . . 
</xsl:template>

请注意,尽管 XSLT 中的“变量”实际上是恒定的——您不是为同一个变量重新分配不同的值,而是在模板内部重新定义它——模板外部myVariable仍然具有 value 111

于 2013-06-12T13:17:49.310 回答
-2

您可以使用 jscript/vbscript 完成您想做的事情。这是使用 Jscript 的示例。

<xsl:stylesheet version="1.0"
               xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
               xmlns="http://www.w3.org/TR/xhtml1/strict"
               xmlns:msxsl='urn:schemas-microsoft-com:xslt' 
               xmlns:var='urn:var' 
               xmlns:JS='urn:JS'
                >
  <xsl:output method="html"/>
  <xsl:variable name="n" select="1"/>
  <xsl:template match="/NewDataSet">
    <html>
      <head>
        <style>
          table{border-collapse:collapse}
          table,td{border:1px solid black;color:black; background-color:white}
          table,th{border:1px solid balck;background-color:black;color:white }
          .rt{color:red}
          .redb{color:yellow; background-color:red;}
          .greenb{color:white;background-color:green;}
        </style>
        <title>EDI validation Result </title>
      </head>
      <body>
        <div font="bold">
          EDI validation result  for the PO <xsl:value-of select="info/pono"/>
        </div>
        <div>
          received from <xsl:value-of select="info/CustomerName"/>
        </div>
        <xsl:variable name='var:hasErrors' select='0'/>
        <xsl:variable name='var:ngoodlines' select='0' />
        <xsl:variable name='var:nbadlines' select='0' />
        <table>
          <th>Position</th>
          <th>Item Code</th>
          <th>UoM</th>
          <th>Ordered Qty.</th>
          <th>Net-Quoted</th>
          <th>Net-Catalog</th>
          <th>Status</th>
          <xsl:for-each select="Table">
            <tr>
              <xsl:choose>
                <xsl:when test="Status !=''">
                  <xsl:value-of disable-output-escaping="yes" select="JS:IncBlines()"/>
                  <td class="redb"><xsl:value-of select="Position"/></td>
                  <td class="redb"><xsl:value-of select="ItemCode"/></td>
                  <td class="redb"><xsl:value-of select="UoM"/></td>
                  <td class="redb"><xsl:value-of select="QtyOrdered"/></td>
                  <td class="redb"><xsl:value-of select="PriceQuoted"/></td>
                  <td class="redb"><xsl:value-of select="Net"/></td>
                  <td class="redb"><xsl:value-of select="Status"/></td>
                </xsl:when>
                <xsl:otherwise>
                  <xsl:value-of select="JS:IncGlines()"/>

                  <td class="greenb"><xsl:value-of select="Position"/></td>
                  <td class="greenb"><xsl:value-of select="ItemCode"/></td>
                  <td class="greenb"><xsl:value-of select="UoM"/></td>
                  <td class="greenb"><xsl:value-of select="QtyOrdered"/></td>
                  <td class="greenb"><xsl:value-of select="PriceQuoted"/></td>
                  <td class="greenb"><xsl:value-of select="Net"/></td>
                  <td class="greenb"><xsl:value-of select="Status"/>OK</td>

                 </xsl:otherwise>
                </xsl:choose>
            </tr>
          </xsl:for-each>
        </table>

        <xsl:if test="JS:GetBlines() > 0"    >

          <div class="rt">
            <p>
              The order validation has failed ,
              The order will not be processesed as there are <xsl:value-of select ="JS:GetBlines()"/> lines in error.
              <xsl:if test="JS:GetGlines() > 0">
                Although there are <xsl:value-of select="JS:GetGlines()"/> line item(s) are that comply the requirements, <p>
                The P.O is rejected as per agreed processing rules.
                     </p>

              </xsl:if>

            </p>  

          </div>

        </xsl:if>


            <xsl:value-of select="JS:GetBlines()"/>
            <xsl:value-of select ="JS:GetGlines()"/>

      </body>
    </html>
  </xsl:template>
  <msxsl:script language='JScript' implements-prefix='JS'>

    <![CDATA[
    var j :int=0;
    var blines:int =0;
    var glines:int=0;
    function Inc(current)
    {j=j+current;

  return  j+current;
    }
    function IncBlines()
    {
     blines++;
    }
    function IncGlines()
    {
    glines++;
    }

    function GetBlines()
    {
    return blines;
    }
    function GetGlines()
    {
    return glines;
    }
]]>
  </msxsl:script>
</xsl:stylesheet>

<NewDataSet>
  <Table>
    <Position>1</Position>
    <ItemCode>691-301-004</ItemCode>
    <QtyOrdered>1</QtyOrdered>
    <PriceQuoted>0.00</PriceQuoted>
    <Net>0.0000</Net>
    <UoM>EA</UoM>
    <Status>Not in Catalog</Status>
  </Table>
  <Table>
    <Position>2</Position>
    <ItemCode>106284-133</ItemCode>
    <QtyOrdered>1</QtyOrdered>
    <PriceQuoted>20.00</PriceQuoted>
    <Net>0.0000</Net>
    <UoM>EA</UoM>
    <Status>Not in Catalog</Status>
  </Table>
  <Table>
    <Position>3</Position>
    <ItemCode>116304-317</ItemCode>
    <QtyOrdered>1</QtyOrdered>
    <PriceQuoted>25.00</PriceQuoted>
    <Net>0.0000</Net>
    <UoM>EA</UoM>
    <Status>Not in Catalog</Status>
  </Table>
  <Table>
    <Position>4</Position>
    <ItemCode>574116-035</ItemCode>
    <QtyOrdered>10</QtyOrdered>
    <PriceQuoted>1598.85</PriceQuoted>
    <Net>1865.5000</Net>
    <QtyApplicable>99999999</QtyApplicable>
    <UoM>EA</UoM>
    <Status>Quoted Price does not match Catalog price</Status>
  </Table>
  <Table>
    <Position>5</Position>
    <ItemCode>110223-301</ItemCode>
    <QtyOrdered>10</QtyOrdered>
    <PriceQuoted>147.88</PriceQuoted>
    <Net>147.8800</Net>
    <QtyApplicable>99999999</QtyApplicable>
    <UoM>EA</UoM>
  </Table>
  <info>
    <baanid>xxx-xxxxxx</baanid>
    <pono>xxx0002987</pono>
    <CustomerName>[xxx-xxxxxx]-xxxxxxxxxxxxxxxxxxxxxxxxx x xxxxx/CustomerName>
  </info>
</NewDataSet>
于 2014-08-16T08:49:56.797 回答