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