[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Returning a value from a template

Subject: Returning a value from a template
From: Narayan <ed_narayanan@xxxxxxxxx>
Date: Tue, 9 Nov 2010 18:07:53 -0800 (PST)
 Returning a value from a template
I have been scratching my head on how to return a value from a called template
which includes a for loop. A snippet of the XML fragment is as follows:
 <Loop-N1>
      <Segment-N1>
         <Element-98>BT</Element-98>
        
<Element-93 xsi:nil="true"/>
         <Element-66>21</Element-66>
        
<Element-67>RA0129937</Element-67>
      </Segment-N1>
   </Loop-N1>
  
<Loop-N1>
      <Segment-N1>
         <Element-98>ST</Element-98>
        
<Element-93>ABC COLUMBUS DIVISION</Element-93>
        
<Element-66>11</Element-66>
         <Element-67>RA0314562</Element-67>
     
</Segment-N1>
   </Loop-N1>

The element <Loop-N1> can occur multiple times.
If one of the <Element-66>'s 
contain a value of "21" then I need to generate
a fixed string value else I need 
to generate another fixed string literal. So
I tried creating a named template 
and calling this from my main template like
a function:

   <xsl:template name="getOrderSource">

    <xsl:for-each
select="/ns0:Transaction-850/ns0:Loop-N1">
        <xsl:if
test='ns0:Segment-N1/ns0:Element-66 = "21"'>
          <xsl:variable
name="ordrSrc" select="NAEDI"/>
        </xsl:if>
    </xsl:for-each>

   
<xsl:choose>
      <xsl:when test='$orderSrc = "NAEDI"'>
        <xsl:text
disable-output-escaping="no">NAEDI</xsl:text>
      </xsl:when>
     
<xsl:otherwise>
        <xsl:text
disable-output-escaping="no">NAEDIBrokerage</xsl:text>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

This was called like:
  <corecom:ID>
            <xsl:call-template name="getOrderSource"/>
  </corecom:ID>
However, I realized that the variable declared inside the for-each is not
visible to the xsl:choose that follows. What I was trying to do is to set a
flag 
to indicate that the element exists and then return the appropriate
string 
literal. Would there be a simpler way to do this? Thanks!

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.