2013-06-12 11 views
6

, XSLT'de küresel değişken bildirin lokal

Ben global alan içinde değer “111” ile bir değişken “degiskenim” ilan edebilir bir değer yeniden atayın. Ancak yerel olarak nasıl bir değer atayabilirim. Ya da bunu başarmanın alternatif bir yolu var mı?

Lütfen

Yardım edin. Teşekkür ederiz. Ravi

+0

Evet, sorununuzu çözmenin alternatif bir yolu var. Sorununuzu açıkladıktan sonra açıklamaktan mutluluk duyacağız (bir çözümde yanlış girişiminiz yerine). –

cevap

6

Bir şablonu içinde aynı değişken yeniden tanımlayabiliriz: XSLT'de o 'değişkenleri' aslında sabit olsa

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

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

Not - Aynı değişkene farklı bir değer yeniden atama değildir , şablonun içinde yeniden tanımlarsınız - şablonun dışında myVariable hala 111 değerine sahip olacaktır.

+9

Bu "aynı değişkeni yeniden tanımlamak" değildir *, aynı ada sahip yeni bir değişken tanımlamaktadır. Ben değişken için atanmış olunca farklı bir değere sahip olamaz olarak – Borodin

+0

sonra bir çözüm olmayacaktır reply..This için teşekkür ederiz "degiskenim" –

+1

@Ravi: doğrudan 'çözüm' vardır - XSLT'de sen değerini değiştiremezsiniz değişkenin Sorunuzu genişletmek için neye ihtiyacınız olduğunu açıklamanız gerekirse, – MiMo

-2

Ne yapmak istediğinizi jscript/vbscript kullanarak gerçekleştirebilirsiniz. İşte Jscript kullanarak örnek.

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