Suppose the data string is stored in certain element like this.
[tt]<data>adamsooleywasheretoaskaquestionaboutxmladamwouldlikearesponse</data>
[/tt]
The way to do it is a standard recursion. Here is a version I sketch---maybe not the best.
[tt]
<xsl:template match="//data">
<xsl:call-template name="substr_count">
<xsl:with-param name="str" select="." />
<xsl:with-param name="sub" select="'adam'" />
<xsl:with-param name="cnt" select="0" />
</xsl:call-template>
<xsl:template name="substr_count">
<xslaram name="str" />
<xslaram name="sub" />
<xslaram name="cnt" />
<xsl:choose>
<xsl:when test="contains($str,$sub)">
<xsl:call-template name="substr_count">
<xsl:with-param name="str" select="substring-after($str,$sub)" />
<xsl:with-param name="sub" select="$sub" />
<xsl:with-param name="cnt" select="$cnt+1" />
</xsl:call-template>
</xsl:when>
<xsltherwise>
<xsl:text>[</xsl:text>
<xsl:value-of select="$cnt" />
<xsl:text>]</xsl:text>
</xsltherwise>
</xsl:choose>
</xsl:template>
</xsl:template>
[/tt]
Between xsl:text are for cosmetic, inside it shows the result.
ps: How much study you do on your own? That looks very like assignment though often not obvious at the beginning.
I can assure you it is not an assignment. I and creating a online task list for work. Have everything working fine except when I display the results say on one user, I get he has done 12 tasks. (Meeting, Web, Course, Ticket, Ticket, Ticket, Web, Meeting, Meeting, Web, Course) each have a time amount for each task. But when I want it to display:
------------------------------------
Meeting - Total time: 2 hours
Web - Total time: 7 hours
Course - Total time: 1 hours
Ticket - Total time: 8 hours
------------------------------------
I get:
------------------------------------
Meeting - Total time: 2 hours
Web - Total time: 7 hours
Course - Total time: 1 hours
Ticket - Total time: 8 hours
Ticket - Total time: 8 hours
Ticket - Total time: 8 hours
Web - Total time: 7 hours
Meeting - Total time: 2 hours
Meeting - Total time: 2 hours
Web - Total time: 7 hours
Course - Total time: 1 hours
------------------------------------
So I get the totals fine but it repeats all occurnces of task with the total time instead of stopping.
So bacisally I am trying anything I can think of for it to display only one.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.