Hello forum!

I'm new to this forum, but I hope someone will take the time to help me, I have been grappling with this for days.
I would very much appreciate it if you could help me understand what I'm doing wrong/where my thinking is off target. I find this much more important than the actual solutions (although they are appreciated too) :-)

TIA
B

The task are:
(as some tasks are similar I have limited the tasks in attached xsl to make it more readable)
1. Find number of cars with automatic transmission ('automat') as part of the string value of the adtext element.
1 Find. number of cars registered before 1999.
2 Find. number of cars registered from 1999 onwards.
3 Find. number of cars lacking registration info.
4 Find average value of cars in each group.

XML sample:

<autoads>
    <ad>
        <type>1</type>
        <name>Honda</name>
        <model>XL 1000 V</model>
        <regyear>2001</regyear>
        <price>129900</price>
        <adtext>2001 Honda XL 1000 V, 8.900 km. bagstertrekk, høyt kåpeglass. Pris kr 129.900,-. automat.  </adtext>
        <addate>20020115</addate>
        <volume>1000</volume>
        <category></category>
    </ad> 
    <ad>
           ETC. ETC:
    </ad>
</autoads>

My XSL:

<xsl:template match="/">
<!-- Trying to count the number of occurences of the word "automat" in the string value of ad/adtext-->
    <xsl:for-each select="/ad/adtext"> 
<!-- By making a new element node so that it may be counted-->
        <xsl:if test="ad/adtext [contains(adtext, 'automat')]">
            <xsl:element name="atuomat"/> 
        </xsl:if>
    </xsl:for-each>
<!-- I then try to count the number of elements and place them in a variable -->
    <xsl:variable name="auto">
            <xsl:value-of select="count(automat)"/>
    </xsl:variable>

<!-- Trying to count cars (type 2s)older than 1999-->
<xsl:for-each select="ad [type = 2]"> 
<!-- Trying to make an element for each car older than 1999 -->
    <xsl:if test="/ad[regyear &lt;1999]">
        <xsl:element name="eldre"/>
    </xsl:if>        
</xsl:for-each>
<!-- Trying to make a variable containing the number of elements made above. -->
    <xsl:variable name="gammel">
        <xsl:value-of select="count(eldre)"/>
    </xsl:variable>

<!-- Trying to count cars with no registeration info -->
<xsl:for-each select="ad [type = 2]"> 
<!-- Trying to make an element for each car without registration info -->
    <xsl:if test="not [/ad/regyear]">
        <xsl:element name="null"/>
    </xsl:if>        
</xsl:for-each>
<!-- Trying to make a variable containing the number of elements made above. -->
    <xsl:variable name="ingen">
        <xsl:value-of select="count(null)"/>
    </xsl:variable>

<!--HTML here  -->
</xsl:template>

Hi,
I was using the same method to count number of elements in my xslt but i am not getting the result. I am using below code instead of for-each loop.:

ABC<xsl:element name"countOfSegments" />DEF<xsl:element name"countOfSegments" />GHI<xsl:element name"countOfSegments" />JKL<xsl:value-of select="count(countOfSegments)" />

Can anybody please tell me the correct way in case i am doing something wrong?

Thanks
Ruchi S

I still have not been able to find a solution to this problem
I believe the problem is that I don't get how the result trees are generated and used during processing. I have been trying to find an explanation on the web, but I must be missing something as I just can't get my head around them.

I also have trouble grasping how to properly nest functions. When to use brackets, parantheses, and when to add a slash in front of an xpath axis or not.

Anyone care to help me out?

This article has been dead for over six months. Start a new discussion instead.