Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • enclave 1 post 21 karma points
    Nov 12, 2010 @ 10:20
    enclave
    0

    Count equals string values

    So i have a xml file

    <ApacheLog>
    <LOGS>
    <Request>GET promotion2.html HTTP/1.0</Request>
    <Reff>www.yahoo.com</Reff>
    </LOGS>
    <LOGS>
    <Request>GET promotion1.html HTTP/1.0</Request>
    <Reff>www.yahoo.com</Reff>
    </LOGS>
    <LOGS>
    <Request>GET promotion1.html HTTP/1.0</Request>
    <Reff>www.google.com</Reff>
    </LOGS>
    </ApacheLog>

    I need to count how many times each promotion is visited , and count distinct reff for each promotion

    <ApacheLog>
    <LOGS>
    <promotion1>2</Request>

    <numReff>2</RemoteHost>

    <promotion2>1</Request>


    <numReff>1</RemoteHost>
    </LOGS>
    </ApacheLog>

    Can someone help me with this transformation.
    Sorry for bad English but is not my native language.

  • Søren Tidmand 129 posts 366 karma points
    Nov 20, 2010 @ 23:37
    Søren Tidmand
    1

    Hi enclave,

    Here's a solution with a readable and sorted output of the Requests with a count of each promotion and a list of all the Reffs. Unfortunately I wasn't able to figure out how to group each single Reff, but hopefully this will help you get an overview of the log-file. FYI: You'll have to post the code in a new xslt file after the <!-- start writing XSLT --> tag and include the macro in a template (or directly on a page). Please note that you will have to put in the URL of your XML log-file in the variable on top.

    Please get back to me if you have any questions.

    All the best,

    Søren

     

    <xsl:variable name="source" select="umbraco.library:GetXmlDocumentByUrl('your-xml-file')"/>
    
    <xsl:key name="request-by_promotion" match="LOGS" use="Request" />
    
    <xsl:template match="/">
        <xsl:for-each select="$source//LOGS[count(. | key('request-by_promotion', Request)[1]) = 1]">
            <xsl:sort select="Request" />
    
            <xsl:apply-templates select="." mode="group" />
            <p>Number of Requests: <xsl:value-of select="count(key('request-by_promotion', Request))"/></p>
    
            <xsl:apply-templates select="key('request-by_promotion', Request)" mode="item">
                <xsl:sort select="Reff" />
            </xsl:apply-templates>
        </xsl:for-each>
    </xsl:template>
    
    <xsl:template match="LOGS" mode="group">
        <!-- Output without the GET and HTTP stuff -->
        <h2><xsl:value-of select="substring-after(substring-before(Request, '.html HTTP/1.0'), 'GET ')" /></h2>
    </xsl:template>
    
    <xsl:template match="LOGS" mode="item">
        <!-- TODO: Output for each item -->
        <xsl:value-of select="Reff" />
        <xsl:if test="not(position() = last())"><br/></xsl:if>
    </xsl:template>
    
  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies