Re: [xsl] help with looping thru children

Subject: Re: [xsl] help with looping thru children
From: "Jay Bryant" <jay@xxxxxxxxxxxx>
Date: Wed, 3 May 2006 13:25:27 -0500
Rather than think in terms of loops, try thinking in terms of templates.

In other words, rather than try to count things and do something each time
some value is incremented (and even for-each doesn't work that way in XSLT),
try doing something each time a certain kind of node is found.

So, rather than

<xsl:for-each select="something">
</xsl:for-each>

try

<xsl:template match="something">
</xsl:template>

FWIW

Jay Bryant
Bryant Communication Services

----- Original Message ----- 
From: "Lyn Stewart-Hunter" <Lyn@xxxxxxxxxxxxxxxx>
To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Wednesday, May 03, 2006 12:07 PM
Subject: [xsl] help with looping thru children


Howdy.  I was able to use some past help to get header data to repeat in
a CSV format, but I then couldn't figure out where to put the for-each
to loop thru all EVENTS (or whatever structure would work).  From the
XML I would like a row in a CSV file for every EVENT (and include the
SUMMARY.REFERRING_URL).

I am also getting the DOWNLOAD on the 'wrong' row (maybe a new template
at that level?) and need to figure out how to get FUNNEL.CONVERSION ID
listed after its EVENT - if that's easy for someone to show me.  But I
am most interesting capturing each EVENT and maintaining the SUMMARY
data for each row - I don't know xml very well, so examples are ideal.

thank you. Lyn

My current output looks like:
2004-04-12 11:54:48 PST,HBX Home,Simple eBook,http://w w
w.google.com/search?q = web +analytics,ENDROW

XML is:
<?xml version='1.0' encoding='utf-8' ?>
<SESSION>
<SUMMARY>
<REFERRING_URL>http://w w w.google.com/search?q = web
+analytics</REFERRING_URL>
<BROWSER> MSIE 6.0</BROWSER>
</SUMMARY>
<EVENTS>
<EVENT>
<TIMESTAMP>2004-04-12 11:54:48 PST</TIMESTAMP>
<VIEW>
<PAGENAME>HBX Home</PAGENAME>
<CONTENT>/Products/HBX</CONTENT>
<RELOADS>1</RELOADS>
</VIEW>
<FUNNELS>
<FUNNEL>
<IS_CONVERSION_LEVEL>3</IS_CONVERSION_LEVEL>
<FUNNEL_ID>1123</FUNNEL_ID>
<FUNNEL_LEVEL>1</FUNNEL_LEVEL>
</FUNNEL>
</FUNNELS>
</EVENT>
<EVENT>
<TIMESTAMP>2004-04-12 11:56:46 PST</TIMESTAMP>
<VIEW>
<PAGENAME> Download Page</PAGENAME>
<CONTENT>/Products/HBX/Downloads</CONTENT>
</VIEW>
<FUNNELS>
<FUNNEL>
<IS_CONVERSION_LEVEL>3</IS_CONVERSION_LEVEL>
<FUNNEL_ID>1123</FUNNEL_ID>
<FUNNEL_LEVEL>3</FUNNEL_LEVEL>
</FUNNEL>
</FUNNELS>
</EVENT>
<EVENT>
<TIMESTAMP>2004-04-12 11:56:58 CST</TIMESTAMP>
<DOWNLOAD>Simple eBook</DOWNLOAD>
</EVENT>
</EVENTS>
</SESSION>
+++++++++++++++++++++
XSL is:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
version="1.0">
<xsl:output method="text"
encoding="ISO-8859-1"/>

<xsl:strip-space elements="*"/>

<xsl:template match="/">
<xsl:apply-templates select="SESSION"/>
</xsl:template>

<xsl:template match="SESSION">
<xsl:apply-templates select="EVENTS"/>
</xsl:template>

<xsl:template match="SUMMARY">
<xsl:value-of select="REFERRING_URL"/>
<xsl:text>,</xsl:text>
</xsl:template>

<xsl:template match="EVENTS">
                <xsl:value-of select="//TIMESTAMP"/>
<xsl:text>,</xsl:text>
                <xsl:value-of select="//PAGENAME"/>
<xsl:text>,</xsl:text>
                <xsl:value-of select="//DOWNLOAD"/>
<xsl:text>,</xsl:text>
<xsl:apply-templates select="../SUMMARY"/>
               <xsl:text>ENDROW&#013;&#010;</xsl:text>

</xsl:template>
</xsl:stylesheet>

Current Thread