xsl-list
[Top] [All Lists]

Re: [xsl] Re: Returning a value from a template

2010-11-10 12:05:19
At 2010-11-10 09:36 -0800, Narayan wrote:
Yes ... don't use the flag.  Something along the lines of:

  <xsl:template name="getOrderSource">
    <xsl:for-each select="/ns0:Transaction-850/ns0:Loop-N1">
      <xsl:choose>
<xsl:when test='ns0:Segment-N1/ns0:Element-66 = "21"'>NAEDI</xsl:when>
        <xsl:otherwise>NAEDIBrokerage</xsl:otherwise>
      </xsl:choose>
    </xsl:for-each>
  </xsl:template>
...
Thanks Ken. The problem with the above approach is that if there are 3 Loop-N1's
then the output would be:
<corecom:ID>NAEDIBrokerageNAEDIBrokerageNAEDIBrokerage</corecom:ID>

Thats why I was trying to set a flag inside the loop and then return a Single
value.

Then you *don't* need the loop at all:

  <xsl:template name="getOrderSource">
    <xsl:choose>
      <xsl:when test='/ns0:Transaction-850/ns0:Loop-N1/
                      ns0:Segment-N1/ns0:Element-66 = "21"'>NAEDI</xsl:when>
      <xsl:otherwise>NAEDIBrokerage</xsl:otherwise>
    </xsl:choose>
  </xsl:template>

In XPath when you address a set of nodes as an operand in a test, the test is repeated for every member of the node set until either a true() value is returned by any member (you aren't told which), or until the node set is exhausted and a false() value is returned.

I hope this helps.

. . . . . . . . . Ken


--
Contact us for world-wide XML consulting & instructor-led training
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/s/
G. Ken Holman                 mailto:gkholman(_at_)CraneSoftwrights(_dot_)com
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>