xsl-list
[Top] [All Lists]

RE: [xsl] xsl:call-template problem

2006-08-22 14:09:03
I want to process <stream_definition> twice and the text values of <PID>
are related. 

-----Original Message-----
From: cknell(_at_)onebox(_dot_)com [mailto:cknell(_at_)onebox(_dot_)com] 
Sent: Tuesday, August 22, 2006 1:59 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: RE: [xsl] xsl:call-template problem

If I understand your requirement, you wish to process each
<stream_definition> with two different templates.

The usual way to do this is by using a "mode" attribute on the templates
and in the <apply-template> opening tag.

So here you want two templates:

<xsl:template match="stream_definition" mode="alpha">
  ... Your stuff goes here ...
</xsl:template>

<xsl:template match="stream_definition" mode="beta">
  ... Your other stuff goes here ...
</xsl:template>

Then you do either:

<xsl:apply-templates select="stream_definition" mode="alpha" />
<xsl:apply-templates select="stream_definition" mode="beta" />

Of course, what value you assign to the various "mode" attributes is up
to you. I used "alpha" and "beta", you may want to use "cat" and "dog",
or any other XML-legal values.



-- 
Charles Knell
cknell(_at_)onebox(_dot_)com - email



-----Original Message-----
From:     Lin, Jessica <jlin(_at_)solekai(_dot_)com>
Sent:     Tue, 22 Aug 2006 11:55:58 -0700
To:       <xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com>
Subject:  [xsl] xsl:call-template problem


Here is the block of xml file. I want to repeat stream twice in
stream_loop and change the SCID to PID with differenct start number by
using xsl:call-template.

  <stream_loop>
    <stream_definition>
      <stream_type>2</stream_type>

      <SCID>100</SCID>
      <descriptors_loop_length>compute</descriptors_loop_length>
      <descriptor_loop>
        <about_descriptor>some description</about_descriptor>
        <additional_descriptor>other description</additional_descriptor>
      </descriptor_loop>
    </stream_definition>
  </stream_loop>


Here is the expected result:
 <stream_loop>
    <stream>
      <stream_type>2</stream_type>

      <PID>4112</SCID>
      <ECM>4113</ECM>
      <descriptors_loop_length>compute</descriptors_loop_length>
      <descriptor_loop>
        <about_descriptor>some description</about_descriptor>
        <additional_descriptor>other description</additional_descriptor>
      </descriptor_loop>
    </stream>
    <stream>
      <stream_type>2</stream_type>

      <PID>4114</SCID>
      <ECM>4115</ECM>
      <descriptors_loop_length>compute</descriptors_loop_length>
      <descriptor_loop>
        <about_descriptor>some description</about_descriptor>
        <additional_descriptor>other description</additional_descriptor>
      </descriptor_loop>
    </stream>
  </stream_loop>



Here is my xslt block:


<xsl:template name="repeat twice">              
  <xsl:param name="base" select="4112"/>
  <xsl:param name="start" select="0"/>
  <xsl:choose>
    <xsl:when test="$start < 2">
      <stream>
        <xsl:for-each select="node()">
          <xsl:choose>
            <xsl:when test="local-name(.)='SCID'">
              <PID>
<xsl:value-of select="$base"/>
              </PID>
              <ECM>
                <xsl:value-of select="$base+1"/>
              </ECM>                                    
            </xsl:when>
            <xsl:otherwise>
              <xsl:copy-of select="."/>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:for-each>
      </stream>                                                         
      <xsl:call-template name="calculate">

        <xsl:with-param name="base" select="$base+$start*2" />
        <xsl:with-param name="start" select="$start+1"/>
      </xsl:call-template>      
    </xsl:when> 
  </xsl:choose>
</xsl:template>


But the real result is not as what I am expecting. Can anyone tell me
what's wrong in my xslt block? Thank a lot.


--- Jessica

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




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


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