2013-06-12 5 views
6

XSLT में वैश्विक चर घोषित करें, एक मूल्य के पुन: असाइन कर स्थानीय स्तर पर

मैं एक मूल्य "111" वैश्विक क्षेत्र में के साथ एक चर "myVariable" घोषणा कर सकते हैं। लेकिन मैं स्थानीय रूप से एक मूल्य फिर से कैसे सौंप सकता हूं। या यह हासिल करने का एक वैकल्पिक तरीका है।

कृपया मदद करें। धन्यवाद। रवि

+0

हां, आपकी समस्या का समाधान करने का एक वैकल्पिक तरीका है। एक बार जब आप अपनी समस्या की व्याख्या करते हैं (समाधान में आपके गलत प्रयास के बजाए) हम इसे समझाएंगे। –

उत्तर

6

आप एक टेम्पलेट के अंदर ही चर फिर से परिभाषित कर सकते हैं:

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

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

नोट कि हालांकि XSLT में 'चर' वास्तव में लगातार कर रहे हैं - आप नहीं एक ही चर के लिए एक अलग मूल्य फिर से बताए जाते हैं , आप टेम्पलेट के अंदर इसे फिर से परिभाषित कर रहे हैं - टेम्पलेट myVariable के बाहर अभी भी 111 मान होगा।

+9

यह * एक ही वैरिएबल को फिर से परिभाषित नहीं कर रहा है * *, यह एक ही नाम के साथ एक नए चर को परिभाषित कर रहा है। – Borodin

+0

उत्तर के लिए धन्यवाद .. यह समाधान नहीं होगा क्योंकि मेरे पास "myVariable" –

+1

@Ravi के लिए असाइन किया गया एक अलग मूल्य नहीं हो सकता है: कोई प्रत्यक्ष 'समाधान' नहीं है - एक्सएसएलटी में आप मूल्य नहीं बदल सकते एक चर के। यदि आप अपने प्रश्न को विस्तारित करते हैं जो आपको प्राप्त करने की आवश्यकता है, तो हम उन समाधानों को प्रस्तावित करने में मदद करने के लिए प्रयास कर सकते हैं जिन्हें चर के – MiMo

-2

जेएसक्रिप्ट/vbscript का उपयोग करके आप जो करना चाहते हैं उसे पूरा कर सकते हैं। जेएसक्रिप्ट का उपयोग कर उदाहरण यहां दिया गया है।

<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> 
संबंधित मुद्दे