xsl-list
[Top] [All Lists]

Re: xsl:apply-template and xsl:for-ech confusion

2003-10-01 05:47:14
ok the solution was infact using

<xsl:apply templates select=".."/>

since there was the child element tblMIMSubsector being processed

thanks a lot for your help guys and sorry for the late duplicate e-mail


regards
Luke

----- Original Message -----
From: "Anton Triest" <anton(_at_)cking(_dot_)be>
To: <xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com>
Sent: Friday, October 01, 2004 2:04 PM
Subject: Re: [xsl] xsl:apply-template and xsl:for-ech confusion


Hi Luke,

You could do that, but you can't use <xsl:apply templates
select="tblMIMCompanies"/>
because the for-each loop already puts you in the context of the
tblMIMCompanies nodes.
I think it should work if you use <xsl:apply templates select="."/>

Or alternatively use apply-templates instead of for-each and use a mode:

<xsl:template match="tblMIM">
    <xsl:apply-templates select="tblMIMCompanies"/>
</xsl:template>

<xsl:template match="tblMIMCompanies">
    <xsl:if test="$searchby=0 and
tblMIMSubSectors[(_at_)subsectorID=$subsector]">
        <xsl:apply-templates select="." mode="output"/>
    </xsl:if>
    <xsl:if test="$searchby=1 and tblMIMSubSectors[(_at_)sectorID=$sector]">
        <xsl:apply-templates select="." mode="output"/>
    </xsl:if>
</xsl:template>

<xsl:template match="tblMIMCompanies" mode="output">
    <xsl:value-of select="@name"/>
    ...
</xsl:template>

Cheers,
Anton


Luke Ambrogio wrote:

Hello guys,

thanks a lot for the great help you gave me with my previous problem,
hopefully this will be as simple to solve.
I have

<xsl:template match="tblMIM">
   <xsl:for-each select="tblMIMCompanies">
       <xsl:choose>
           <xsl:when test="$searchby=0">
               <xsl:if 
test="tblMIMSubSectors[(_at_)subsectorID=$subsector]">
                   <xsl:value-of select="@name"/>
                   ...
               </xsl:if>
           </xsl:when>
           <xsl:when test="$searchby=1">
               <xsl:if test="tblMIMSubSectors[(_at_)sectorID=$sector]">
                   <xsl:value-of select="@name"/>
                   ...
               </xsl:if>
           </xsl:when>
       </xsl:choose>
   </xsl:for-each>
</xsl:template>

i would like to change it to something like the code below, which doesn't
output anything. This way i don't need to repeat the inner most code
since
its the same for each. any ideas?

<xsl:template match="tblMIM">
   <xsl:for-each select="tblMIMCompanies">
       <xsl:choose>
           <xsl:when test="$searchby=0">
               <xsl:if 
test="tblMIMSubSectors[(_at_)subsectorID=$subsector]">
                   <xsl:apply templates select="tblMIMCompanies"/>
               </xsl:if>
           </xsl:when>
           <xsl:when test="$searchby=1">
               <xsl:if test="tblMIMSubSectors[(_at_)sectorID=$sector]">
                   <xsl:apply templates select="tblMIMCompanies"/>
               </xsl:if>
           </xsl:when>
       </xsl:choose>
   </xsl:for-each>
</xsl:template>

<xsl:template match="tblMIMCompanies">
   <xsl:value-of select="@name"/>
   ...
</xsl:template>

the xml looks like this

<tblMIM>
   <tblMIMCompanies name="A Ltd" ...>
       <tblMIMSubSectors subsectorID="55" sectorID="3"/>
   </tblMIMCompanies>
   <tblMIMCompanies name="Z Ltd" ...>
       <tblMIMSubSectors subsectorID="56" sectorID="3"/>
   </tblMIMCompanies>
</tblMim>


regards
Luke Ambrogio

p.s. thanks in advance



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