neerajkumar.in 0 Newbie Poster
I have a component in which xsl is reading values from replicant of a xml. I am stuck as xsl don't provide for loop.

Here I am checking the condition based on current position of replicant values. But the value of position is not changing as it doesnt iterate based on iteration of count of replicant.

For testing purpose I have hard coded the values of pos, then condition satisfies and output seems to come fine.

Can anyone have idea how to get the current position and compare everytime with the iteration of count.

I want to iterate the position and based on position and compare the value of position by iterating the value of count.

If we consider the xml(dcr)
//if pos is 1
Then output should comes like:

file(test2).stop()
file(test3).stop()
file(test4).stop()
file(test5).stop()
file(test6).stop()
file(test7).stop()

and if pos is 2

file(test1).stop()
file(test3).stop()
file(test4).stop()
file(test5).stop()
file(test6).stop()
file(test7).stop()

--for.xsl--

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="html"/>

<xsl:template match="/">

            <xsl:variable name="mycount">
            <xsl:value-of select="count(record/item[@name='Products']/value/item[@name='DetailsContainer']/value/item[@name='DetailDescriptionContainer']/value/item[@name='VideoDescriptionContainer']/value/item[@name='BrowseVideoFile']/value[text()])"/>               
            </xsl:variable>

            <xsl:call-template name="for.loop">
                    <xsl:with-param name="i">1</xsl:with-param>
                    <xsl:with-param name="count"><xsl:value-of select="$mycount"/></xsl:with-param>
            </xsl:call-template>

</xsl:template>

<!--begin_: Define_The_Output_Loop -->

<xsl:template name="for.loop">

        <xsl:param name="i"/>
        <xsl:param name="count"/>       

        <xsl:variable name="pos">
                <!--<xsl:for-each select="record/item[@name='Products']/value/item[@name='DetailsContainer']/value/item[@name='DetailDescriptionContainer']/value/item[@name='VideoDescriptionContainer']/value">
                                <xsl:value-of select="position()"/>
                </xsl:for-each>-->
                <xsl:value-of select="'3'"/>
        </xsl:variable> 
           <br/>
           <xsl:variable name="test">test</xsl:variable>  
        <xsl:if test="$i <= $count">
                <xsl:if test="$pos !=$i">
                    <xsl:text disable-output-escaping="yes"><![CDATA[file(]]></xsl:text><xsl:value-of select="concat($test,$i)" /><xsl:text disable-output-escaping="yes"><![CDATA[).stop()]]></xsl:text><br/>
                </xsl:if>
        </xsl:if>

                    <xsl:if test="$i <= $count">
                        <xsl:call-template name="for.loop">                                                                     
                                <xsl:with-param name="i">
                                <xsl:value-of select="$i + 1"/>
                                </xsl:with-param>
                                <xsl:with-param name="count">
                                <xsl:value-of select="$count"/>
                                </xsl:with-param>
                        </xsl:call-template>
                    </xsl:if>
</xsl:template>

</xsl:stylesheet>

----test.xml-----

<?xml version="1.0" encoding="UTF-8"?>

<?xml-stylesheet type="text/xsl" href="for.xsl"?>

<record name="advance" type="content">
        <item name="Products">
                <value>
                    <item name="DetailsContainer">
                            <value>
                                <item name="DetailDescriptionContainer">
                                    <value>
                                        <item name="VideoDescriptionContainer">
                                            <value>
                                                <item name="BrowseVideoFile"><value>/Videos/advance-091911.flv</value></item>
                                                <item name="BrowseVideoFile"><value>/Videos/full-demo-092211.flv</value></item>
                                            </value>
                                            <value>
                                                <item name="BrowseVideoFile"><value>/Videos/092211.flv</value></item>
                                            </value>
                                            <value>
                                                <item name="BrowseVideoFile"><value>/Videos/091511.flv</value></item>
                                            </value>
                                            <value>
                                                <item name="BrowseVideoFile"><value>/Videos/091511.flv</value></item>
                                            </value>
                                        </item>
                                    </value>
                                </item>
                            </value>
                        <value>
                                <item name="DetailDescriptionContainer">
                                    <value>
                                        <item name="VideoDescriptionContainer">
                                            <value>
                                                <item name="BrowseVideoFile"><value>/Videos/1911.flv</value></item>
                                                <item name="BrowseVideoFile"><value>/Videos/3211.flv</value></item>
                                            </value>
                                            <value>
                                                <item name="BrowseVideoFile"><value></value></item>
                                            </value>
                                        </item>
                                    </value>
                                </item>
                        </value>
                    </item>
                </value>
        </item>
</record>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.