Ganglia Network monitoring Calculate values out of rrd files - rrdtool

Im searching for some documentary but i couldnt really find anything and im really confused about the network monitoring in Ganglia. So i want to know how much network traffic my hosts have.
If i use the webinterface im seeing this graph :
That is already kind of confusing for me since it says Bytes/sec on the left but then theres M for Megabyte i guess and the in is in K so KiloBytes i guess? Well so far so good this graph doesnt give me to much details so im checking the bytes_out.rrd in my Ganglia directory to see how much MB were send out in Detail. So i got these Data :
<!-- 2014-08-13 11:44:00 CEST / 1407923040 --> <row><v>7.7329800000e+03</v></row>
<!-- 2014-08-13 11:44:15 CEST / 1407923055 --> <row><v>8.2289393333e+03</v></row>
<!-- 2014-08-13 11:44:30 CEST / 1407923070 --> <row><v>8.7957500000e+03</v></row>
<!-- 2014-08-13 11:44:45 CEST / 1407923085 --> <row><v>1.4574438000e+04</v></row>
<!-- 2014-08-13 11:45:00 CEST / 1407923100 --> <row><v>2.3242470000e+04</v></row>
<!-- 2014-08-13 11:45:15 CEST / 1407923115 --> <row><v>2.3242470000e+04</v></row>
<!-- 2014-08-13 11:45:30 CEST / 1407923130 --> <row><v>2.3145348820e+06</v></row>
<!-- 2014-08-13 11:45:45 CEST / 1407923145 --> <row><v>5.7514735000e+06</v></row>
<!-- 2014-08-13 11:46:00 CEST / 1407923160 --> <row><v>5.7514735000e+06</v></row>
<!-- 2014-08-13 11:46:15 CEST / 1407923175 --> <row><v>7.4439770000e+06</v></row>
<!-- 2014-08-13 11:46:30 CEST / 1407923190 --> <row><v>1.0828984000e+07</v></row>
<!-- 2014-08-13 11:46:45 CEST / 1407923205 --> <row><v>8.8717527333e+06</v></row>
<!-- 2014-08-13 11:47:00 CEST / 1407923220 --> <row><v>3.4893667500e+06</v></row>
<!-- 2014-08-13 11:47:15 CEST / 1407923235 --> <row><v>3.4893667500e+06</v></row>
<!-- 2014-08-13 11:47:30 CEST / 1407923250 --> <row><v>8.6100076167e+06</v></row>
<!-- 2014-08-13 11:47:45 CEST / 1407923265 --> <row><v>2.2691770000e+07</v></row>
<!-- 2014-08-13 11:48:00 CEST / 1407923280 --> <row><v>2.2691770000e+07</v></row>
<!-- 2014-08-13 11:48:15 CEST / 1407923295 --> <row><v>2.2899696800e+07</v></row>
<!-- 2014-08-13 11:48:30 CEST / 1407923310 --> <row><v>2.3731404000e+07</v></row>
<!-- 2014-08-13 11:48:45 CEST / 1407923325 --> <row><v>2.6172286400e+07</v></row>
<!-- 2014-08-13 11:49:00 CEST / 1407923340 --> <row><v>3.5935816000e+07</v></row>
<!-- 2014-08-13 11:49:15 CEST / 1407923355 --> <row><v>3.5935816000e+07</v></row>
<!-- 2014-08-13 11:49:30 CEST / 1407923370 --> <row><v>2.8771658410e+07</v></row>
<!-- 2014-08-13 11:49:45 CEST / 1407923385 --> <row><v>1.1502805000e+05</v></row>
<!-- 2014-08-13 11:50:00 CEST / 1407923400 --> <row><v>1.1502805000e+05</v></row>
<!-- 2014-08-13 11:50:15 CEST / 1407923415 --> <row><v>1.1158186333e+05</v></row>
<!-- 2014-08-13 11:50:30 CEST / 1407923430 --> <row><v>1.0468949000e+05</v></row>
<!-- 2014-08-13 11:50:45 CEST / 1407923445 --> <row><v>9.9945940667e+04</v></row>
<!-- 2014-08-13 11:51:00 CEST / 1407923460 --> <row><v>8.6901180000e+04</v></row>
<!-- 2014-08-13 11:51:15 CEST / 1407923475 --> <row><v>8.6901180000e+04</v></row>
<!-- 2014-08-13 11:51:30 CEST / 1407923490 --> <row><v>7.7706996000e+04</v></row>
<!-- 2014-08-13 11:51:45 CEST / 1407923505 --> <row><v>5.2422990000e+04</v></row>
<!-- 2014-08-13 11:52:00 CEST / 1407923520 --> <row><v>5.2422990000e+04</v></row>
<!-- 2014-08-13 11:52:15 CEST / 1407923535 --> <row><v>5.5379930000e+04</v></row>
<!-- 2014-08-13 11:52:30 CEST / 1407923550 --> <row><v>6.1293810000e+04</v></row>
<!-- 2014-08-13 11:52:45 CEST / 1407923565 --> <row><v>6.1999703333e+04</v></row>
<!-- 2014-08-13 11:53:00 CEST / 1407923580 --> <row><v>6.3940910000e+04</v></row>
<!-- 2014-08-13 11:53:15 CEST / 1407923595 --> <row><v>6.3940910000e+04</v></row>
<!-- 2014-08-13 11:53:30 CEST / 1407923610 --> <row><v>4.8976235333e+04</v></row>
<!-- 2014-08-13 11:53:45 CEST / 1407923625 --> <row><v>7.8233800000e+03</v></row>
<!-- 2014-08-13 11:54:00 CEST / 1407923640 --> <row><v>7.8233800000e+03</v></row>
<!-- 2014-08-13 11:54:15 CEST / 1407923655 --> <row><v>7.8233800000e+03</v></row>
<!-- 2014-08-13 11:54:30 CEST / 1407923670 --> <row><v>7.8233800000e+03</v></row>
<!-- 2014-08-13 11:54:45 CEST / 1407923685 --> <row><v>7.8233800000e+03</v></row>
<!-- 2014-08-13 11:55:00 CEST / 1407923700 --> <row><v>7.8233800000e+03</v></row>
<!-- 2014-08-13 11:55:15 CEST / 1407923715 --> <row><v>7.8233800000e+03</v></row>
<!-- 2014-08-13 11:55:30 CEST / 1407923730 --> <row><v>7.8233800000e+03</v></row>
<!-- 2014-08-13 11:55:45 CEST / 1407923745 --> <row><v>7.8233800000e+03</v></row>
<!-- 2014-08-13 11:56:00 CEST / 1407923760 --> <row><v>7.8233800000e+03</v></row>
<!-- 2014-08-13 11:56:15 CEST / 1407923775 --> <row><v>7.8233800000e+03</v></row>
<!-- 2014-08-13 11:56:30 CEST / 1407923790 --> <row><v>7.8233800000e+03</v></row>
<!-- 2014-08-13 11:56:45 CEST / 1407923805 --> <row><v>7.8233800000e+03</v></row>
<!-- 2014-08-13 11:57:00 CEST / 1407923820 --> <row><v>7.8233800000e+03</v></row>
<!-- 2014-08-13 11:57:15 CEST / 1407923835 --> <row><v>7.8233800000e+03</v></row>
<!-- 2014-08-13 11:57:30 CEST / 1407923850 --> <row><v>7.8233800000e+03</v></row>
<!-- 2014-08-13 11:57:45 CEST / 1407923865 --> <row><v>7.8233800000e+03</v></row>
<!-- 2014-08-13 11:58:00 CEST / 1407923880 --> <row><v>7.8233800000e+03</v></row>
<!-- 2014-08-13 11:58:15 CEST / 1407923895 --> <row><v>7.8233800000e+03</v></row>
<!-- 2014-08-13 11:58:30 CEST / 1407923910 --> <row><v>7.8273046667e+03</v></row>
<!-- 2014-08-13 11:58:45 CEST / 1407923925 --> <row><v>7.8822500000e+03</v></row>
<!-- 2014-08-13 11:59:00 CEST / 1407923940 --> <row><v>7.8822500000e+03</v></row>
<!-- 2014-08-13 11:59:15 CEST / 1407923955 --> <row><v>7.8822500000e+03</v></row>
<!-- 2014-08-13 11:59:30 CEST / 1407923970 --> <row><v>7.8822500000e+03</v></row>
<!-- 2014-08-13 11:59:45 CEST / 1407923985 --> <row><v>7.8822500000e+03</v></row>
<!-- 2014-08-13 12:00:00 CEST / 1407924000 --> <row><v>7.8822500000e+03</v></row>
<!-- 2014-08-13 12:00:15 CEST / 1407924015 --> <row><v>7.8822500000e+03</v></row>
<!-- 2014-08-13 12:00:30 CEST / 1407924030 --> <row><v>7.8822500000e+03</v></row>
<!-- 2014-08-13 12:00:45 CEST / 1407924045 --> <row><v>7.8822500000e+03</v></row>
So there should be some traffic around 6-8MB right before 12:00. But i cant see how that value shows that. I calculated the value at 11:47:45 for example.
If i take the E+07 as ^7 i get something around 309,XX so what should that be? if i take it as decimals i get something around 22691770 if i think its Bytes or Kilobytes and divid it by 1024 i will end up at 21,XX which isnt my 6-8MB aswell. So how do i calculate these values?
I got that these are the avg values for a 15 second period. But it should be Bytes/Sec if i see the graphs writing. But i dont really see how that numbers can be around 6-8mb/s.
Anyone knows how to calculate or where to find some detailed documentation? I used rrdtool dump btw to get these values ...

The 'E+07' notation to which you are referring, is interpreted as 'times 10 to the 7th power.'
So, in your example,
2.2691770000e+07
would equal 22,692,770. That number, also, is not evident in the graph; however, I believe the graph does some amount of aggregation, perhaps one new plot point per minute...? So I imagine you're going to see discrepancies.
When I averaged the 4 values for the minute of 11:47, I got around 9.6M.

Related

Trying to take an ATOM feed and parse out a section written in XHTML in XSLT format

I am trying to take an NOAA RSS feed (NOAA site says it uses ATOM and CAPS) and convert it for SharePoint using XSLT. I am new to this and have limited experience working in XSLT. Here is a sample of the feed.
<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom"
xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
xmlns:georss="http://www.georss.org/georss">
<id>urn:uuid:9ae4ae29-830f-4870-bace-0f70984b76bd</id><title>
TSUNAMI INFORMATION STATEMENT NUMBER 1 </title>
<updated>2022-01-29T03:00:32Z</updated>
<author>
<name>NWS PACIFIC TSUNAMI WARNING CENTER HONOLULU HI</name>
<uri>http://ntwc.arh.noaa.gov/</uri>
<email>ntwc#noaa.gov</email>
</author>
<icon>http://ntwc.arh.noaa.gov/images/favicon.ico</icon>
<link type="application/atom+xml" rel="self" title="self"
href="http://ntwc.arh.noaa.gov/events/xml/PAAQAtom.xml"/>
<link rel="related" title="Energy Map"
<entry>
<title>KERMADEC ISLANDS REGION</title><updated>2022-01-29T03:00:32Z</updated>
<geo:lat>-29.751</geo:lat>
<geo:long>-174.709</geo:long>
<summary type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<strong>Category:</strong> Information<br/>
<strong>Bulletin Issue Time: </strong> 2022.01.29 03:00:32 UTC
<br/><strong>Preliminary Magnitude: </strong>6.6(Mwp)<br/>
<strong>Lat/Lon: </strong>-29.751 / -174.709<br/>
<strong>Affected Region: </strong>KERMADEC ISLANDS REGION<br/>
</div>
</summary>
</entry>
</feed>
My problem is trying to convert the "summary type=xhtml" section into a readable format (like below) instead of a long run-on sentence.
CATEGORY: Information
BULLETIN ISSUE TIME:
PRELIMINARY MAGNITUDE:
Can someone provide me with some suggestions on how to parse the information in XSLT?
Thank you in advance.
AFAIK there is no standard format for the contents of an Atom summary. If your data provider adheres to the format shown in your example, then - given a well-formed XML input such as:
XML
<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom"
xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
xmlns:georss="http://www.georss.org/georss">
<id>urn:uuid:9ae4ae29-830f-4870-bace-0f70984b76bd</id><title>
TSUNAMI INFORMATION STATEMENT NUMBER 1 </title>
<updated>2022-01-29T03:00:32Z</updated>
<author>
<name>NWS PACIFIC TSUNAMI WARNING CENTER HONOLULU HI</name>
<uri>http://ntwc.arh.noaa.gov/</uri>
<email>ntwc#noaa.gov</email>
</author>
<icon>http://ntwc.arh.noaa.gov/images/favicon.ico</icon>
<link type="application/atom+xml" rel="self" title="self"
href="http://ntwc.arh.noaa.gov/events/xml/PAAQAtom.xml"/>
<entry>
<title>KERMADEC ISLANDS REGION</title><updated>2022-01-29T03:00:32Z</updated>
<geo:lat>-29.751</geo:lat>
<geo:long>-174.709</geo:long>
<summary type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<strong>Category:</strong> Information<br/>
<strong>Bulletin Issue Time: </strong> 2022.01.29 03:00:32 UTC
<br/><strong>Preliminary Magnitude: </strong>6.6(Mwp)<br/>
<strong>Lat/Lon: </strong>-29.751 / -174.709<br/>
<strong>Affected Region: </strong>KERMADEC ISLANDS REGION<br/>
</div>
</summary>
</entry>
</feed>
you could do something like:
XSLT 1.0
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:a="http://www.w3.org/2005/Atom"
xmlns:x="http://www.w3.org/1999/xhtml">
<xsl:output method="text" encoding="UTF-8" />
<xsl:template match="/a:feed">
<xsl:for-each select="a:entry/a:summary/x:div/x:strong">
<xsl:value-of select="." />
<xsl:value-of select="normalize-space(following-sibling::text()[1])" />
<xsl:text>
</xsl:text>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
to get:
Result
Category:Information
Bulletin Issue Time: 2022.01.29 03:00:32 UTC
Preliminary Magnitude: 6.6(Mwp)
Lat/Lon: -29.751 / -174.709
Affected Region: KERMADEC ISLANDS REGION

Truncate decimal places without rounding

I want to truncate all the decimal places using xslt.
The input and expected values are below.
17.99 -> 17
19.01 -> 19
18.0 -> 18
I used
<xsl:value-of select='format-number(17.99, "0")' />
But it gives 18 for 17.99. That mean, this rounding the number.
How can I change xslt so that output message is populating only with truncating decimal places and without rounding? Could you please anyone guide me?
You can use floor here
<xsl:value-of select='format-number(floor(17.99), "0")' /> <!-- 17 -->
<xsl:value-of select='format-number(floor(19.01), "0")' /> <!-- 19 -->
<xsl:value-of select='format-number(floor(18.0), "0")' /> <!-- 18 -->
In fact, you might not even need the format-number here
<xsl:value-of select='floor(17.99)' /> <!-- 17 -->
<xsl:value-of select='floor(19.01)' /> <!-- 19 -->
<xsl:value-of select='floor(18.0)' /> <!-- 18 -->

XSL if column X is character X the do this else do that

-XSL Version 1.0 -
I have an XSL file that was created by someone that no longer works at my company and of course we need to change the XSL. I have never used XSL but did some searching and believe I can perform the function needed by updating the XSL with a choose function.
-Issue-
We have a field that was changed from a leading character count of 13 to 11 but we need to capture both for some time period. It was decided to trim the two leading characters of the year. The values will remain constant up to the slash "/" at either 13 or 11 characters, characters after can vary from 5-13 characters.
13 characters CTM08G2012001/0001
11 characters CTM08G12001/0001
I want to check to see if the 12th character is a "/" and if it is use the first 11 characters and if it is not use the first 13 characters. Here is the code for the function.
Where would I put the choose/otherwise function? There appears to be several that repeat themselves and this confuses me.
How do I capture the "/" in the specific string?
I will continue to research and do apologize for not having a list of things tried as I am not sure where to even start.
<func:function name="func:getProjClaimNo">
<xsl:param name='Proj' />
<xsl:param name='Claim' />
<xsl:variable name="isNUMB" select="'1234567890'"/>
<xsl:variable name="vProj1" select="substring($Proj, 8, 1)"/>
<xsl:variable name="vProj2" select="substring($Proj, 9, 1)"/>
<xsl:choose> <!-- 1 -->
<xsl:when test="contains($isNUMB,$vProj1)"> <!-- 1 -->
<xsl:choose> <!-- 2 -->
<xsl:when test="contains($isNUMB,$vProj2)"> <!-- 2 -->
<xsl:variable name="vProj3" select="number(substring($Proj, 8, 2))"/>
<xsl:choose> <!-- 3 -->
<xsl:when test="$vProj3 > 8"> <!-- 3 -->
<func:result select="$Proj"/>
</xsl:when> <!-- 3 -->
<xsl:otherwise> <!-- 3 -->
<!-- May need to check to see if claim number is empty or if proj in table -->
<xsl:choose>
<!-- 4 -->
<xsl:when test="$Claim=''"> <!-- 4 -->
<func:result select="substring($Claim, 1, 13)"/>
</xsl:when> <!-- 4 -->
<xsl:otherwise> <!-- 4 -->
<func:result select="substring($Claim, 1, 13)"/>
</xsl:otherwise> <!-- 4 -->
</xsl:choose> <!-- 4 -->
</xsl:otherwise> <!-- 3 -->
</xsl:choose> <!-- 3 -->
</xsl:when> <!-- 2 -->
<xsl:otherwise> <!-- 2 -->
<!-- May need to check to see if claim number is empty -->
<xsl:choose> <!-- 5 -->
<xsl:when test="$Claim=''"> <!-- 5 -->
<func:result select="substring($Claim, 1, 13)"/>
</xsl:when> <!-- 5 -->
<xsl:otherwise> <!-- 5 -->
<func:result select="substring($Claim, 1, 13)"/>
</xsl:otherwise> <!-- 5 -->
</xsl:choose> <!-- 5 -->
</xsl:otherwise> <!-- 2 -->
</xsl:choose> <!-- 2 -->
</xsl:when> <!-- 1 -->
<xsl:otherwise> <!-- 1 -->
<!-- May need to check to see if claim number is empty -->
<xsl:choose> <!-- 6 -->
<xsl:when test="$Claim=''"> <!-- 6 -->
<func:result select="substring($Claim, 1, 13)"/>
</xsl:when> <!-- 6 -->
<xsl:otherwise> <!-- 6 -->
<func:result select="substring($Claim, 1, 13)"/>
</xsl:otherwise> <!-- 6 -->
</xsl:choose> <!-- 6 -->
</xsl:otherwise> <!-- 1 -->
</xsl:choose> <!-- 1 -->
</func:function>
I don't see where that "field" is in your stylesheet snippet. In general, you can do something like this:
<xsl:choose>
<xsl:when test="substring($yourfield, 12, 1) ='/'">
<xsl:value-of select="substring($yourfield, 1, 11)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="substring($yourfield, 1, 13)"/>
</xsl:otherwise>
</xsl:choose>
or, more succinctly:
<xsl:value-of select="substring($yourfield, 1, 13-2*(substring($yourfield, 12, 1) ='/'))"/>
However, If I understand correctly, it could be much simpler:
<xsl:value-of select="substring-before($yourfield, '/')"/>

xslt not transforming xml correctly in browser

I have the following XML:
<item>
<title>Testing WebForm</title>
<link>http://linkurlhere.com</link>
<description>
<div class="field field-name-body field-type-text-with-summary
field-label-hidden"><div class="field-items"><div class="field-item even"
property="content:encoded"><div style="background-color: white; width: 100%;">
<div id="prize" style="background-color: yellow; color: #660000; font-weight:
bold; width: 200px;">Prize here</div>
</div>
<div id="startDate">Start Date: January 1, 2013</div>
<div id="endDate">End Date: January 1, 2014</div>
<p></p>
<p>Thanks for playing please take the survey - mock intro</p>
</div></div></div></description>
</item>
And I am rendering it with the following XSLT:
<xsl:template match="rss/channel">
<div id="surveyList">
<p> Please
click on the survey below and complete the survey.</p>
<xsl:for-each select="item">
<div id="surveyItem">
<div id="thePrize">
<xsl:apply-templates select="description" />
</div>
<a id="surveyLink">
<xsl:attribute name="href">
<xsl:value-of select="link"
disable-output-escaping="yes" />
</xsl:attribute>
<xsl:attribute name="target">_blank</xsl:attribute>
<xsl:attribute name="title">Click to complete this survey</xsl:attribute>
<xsl:value-of select="title" disable-output-escaping="yes" />
</a>
<br />
</div>
</xsl:for-each>
</div>
</xsl:template>
<xsl:template match="rss/channel/item/description" name="description">
<xsl:value-of select=".//div[#id='prize']" disable-output-escaping="yes" />
</xsl:template>
When I run this through an IDE such as Altova, and transform it, it shows up correctly with the div prize text. However, when I build out the webapp and deploy it either locally on tomcat 6.0 or on an actual webserver the prize does not show up, and it is not in the source when I view the page.
I have tried multiple browsers to no avail. Is this a simple setup problem with my XSLT page?
Thanks.
Updated below with complete XML including RSS elements:
<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xml:base="http://drupal-survey.url" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
<title>drupal-survey.url</title>
<link>http://drupal-survey.url</link>
<description></description>
<language>en</language>
<item>
<title>Testing WebForm</title>
<link>urlLink here</link>
<description>
<div class="field field-name-body field-type-text-with-summary field-label-hidden">
<div class="field-items"><div class="field-item even" property="content:encoded">
<div style="background-color: white; width: 100%;">
<div id="prize" style="background-color: yellow; color: #660000; font-weight: bold; width: 200px;">$1000 Gift Card to McDonald's</div>
</div>
<div id="startDate">Start Date: January 1, 2013</div>
<div id="endDate">End Date: January 1, 2014</div>
<p>Thanks for playing please take the survey - mock intro</p>
</div></div></div></description>
<pubDate>Mon, 25 Feb 2013 19:12:48 +0000</pubDate>
<dc:creator>admin</dc:creator>
<guid isPermaLink="false">6 at http://drupal-survey.url</guid>
</item>
<item>
<title>sss162 test</title>
<link>http://drupal-survey.url/sss162/test</link>
<description><div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even" property="content:encoded"><p>This is a testing paragraph</p>
<p>this is also</p>
</div></div></div></description>
<pubDate>Thu, 10 May 2012 19:24:43 +0000</pubDate>
<dc:creator>sss162</dc:creator>
<guid isPermaLink="false">4 at http://drupal-survey.url</guid>
</item>
<item>
<title>Orientation Survey</title>
<link>http://drupal-survey.url</link>
<description><div class="field field-name-body field-type-text-with-summary field-label-hidden">
<div class="field-items"><div class="field-item even" property="content:encoded"><div id="startDate">Start Date: January 1, 2013</div>
<div id="endDate">End Date: January 1, 2014</div>
<p>This may be the brief explanation paragraph.</p>
</div></div></div></description>
<pubDate>Thu, 10 May 2012 17:11:38 +0000</pubDate>
<dc:creator>admin</dc:creator>
<guid isPermaLink="false">2 at http://drupal-survey.url</guid>
</item>
</channel>
</rss>

XSLT commenting system

I'm trying to build a commenting system with XSLT. Here's the XML input for comments already submitted:
<in:inputs xmlns:in="http://www.composite.net/ns/transformation/input/1.0">
<!-- Input Parameter, XPath /in:inputs/in:param[#name='story_id'] -->
<in:param name="story_id">182485599</in:param>
<!-- Function Call Result (0 ms), XPath /in:inputs/in:result[#name='LoggedInWebUserID'] -->
<in:result name="LoggedInWebUserID">233459</in:result>
<!-- Function Call Result (9 ms), XPath /in:inputs/in:result[#name='XML_Comment']/root -->
<in:result name="XML_Comment">
<root xmlns="">
<Comments CommentID="1" ResponseCommentID="0" WebUserID="123456" FULL_NAME="Osikhuemhe Abulume" Comment="test comment!!!!" DateSubmitted="Feb 20 2013 1:34PM"/>
<Comments CommentID="2" ResponseCommentID="0" WebUserID="261337" FULL_NAME="Phillip Lowe" Comment="test comment2!!!!" DateSubmitted="Feb 20 2013 5:14PM"/>
<Comments CommentID="3" ResponseCommentID="1" WebUserID="000007" FULL_NAME="Norman Abbott" Comment="my response" DateSubmitted="Feb 20 2013 5:14PM"/>
<Comments CommentID="4" ResponseCommentID="0" WebUserID="233459" FULL_NAME="Tamara Failor" Comment="Not impressed..." DateSubmitted="Feb 20 2013 4:10PM"/>
<Comments CommentID="5" ResponseCommentID="0" WebUserID="233459" FULL_NAME="Tamara Failor" Comment="blah blah blah. " DateSubmitted="Feb 20 2013 4:11PM"/>
<Comments CommentID="6" ResponseCommentID="0" WebUserID="233459" FULL_NAME="Tamara Failor" Comment="dfsfs" DateSubmitted="Feb 20 2013 4:14PM"/>
<Comments CommentID="7" ResponseCommentID="5" WebUserID="233459" FULL_NAME="Tamara Failor" Comment="this is a response to blah blah blah." DateSubmitted="Feb 20 2013 4:52PM"/>
<Comments CommentID="8" ResponseCommentID="3" WebUserID="233459" FULL_NAME="Tamara Failor" Comment="I don't agree with Norman. Terrible response." DateSubmitted="Feb 20 2013 5:39PM"/>
<Comments CommentID="9" ResponseCommentID="4" WebUserID="233459" FULL_NAME="Tamara Failor" Comment="I'm impressed." DateSubmitted="Feb 20 2013 5:43PM"/>
<Comments CommentID="10" ResponseCommentID="1" WebUserID="233459" FULL_NAME="Tamara Failor" Comment="I've got something to say!" DateSubmitted="Feb 20 2013 6:34PM"/>
</root>
</in:result>
This should work like any other commenting system for news stories (see: http://www.npr.org/2013/02/20/172384724/when-a-bad-economy-means-working-forever)
That is - new comments (ResponseCommentID = 0) would always be pushed to the left.
Responses to these comments would sit indented underneath. (i don't care about indentions right now. I would like to get replies to comments to fall underneath each other)
There are two parts where I'm stuck. The first part is how each post should be called:
<xsl:variable name="story_id" select="/in:inputs/in:param[#name='story_id']" />
<xsl:variable name="root" select="/in:inputs/in:result[#name='XML_Comment']/root" />
<xsl:for-each select="$root/Comments[#ResponseCommentID=0]">
<!-- call the template to plot the first comment down -->
<xsl:call-template name="thecomment">
<xsl:with-param name="CommentID"><xsl:value-of select="#CommentID" /></xsl:with-param>
<xsl:with-param name="ResponseCommentID"><xsl:value-of select="#ResponseCommentID" /></xsl:with-param>
</xsl:call-template>
<!-- if the comment has any responses, put those underneath the root -->
<xsl:for-each select="$root/Comments[current()/#CommentID = $root/Comments/#ResponseCommentID]">
<xsl:call-template name="thecomment">
<xsl:with-param name="CommentID"><xsl:value-of select="#CommentID" /></xsl:with-param>
<xsl:with-param name="ResponseCommentID"><xsl:value-of select="#ResponseCommentID" /></xsl:with-param>
</xsl:call-template>
</xsl:for-each>
The (also very wrong) ending recursion part of the template:
<xsl:if test="#CommentID = $root/Comments/#ResponseCommentID">
<xsl:call-template name="thecomment">
<xsl:with-param name="CommentID"><xsl:attribute name="value"><xsl:value-of select="#CommentID[#CommentID = $root/Comments/#ResponseCommentID]" /></xsl:with-param>
<xsl:with-param name="ResponseCommentID"><xsl:attribute name="value"><xsl:value-of select="#ResponseCommentID[#CommentID = $root/Comments/#ResponseCommentID]" /></xsl:with-param>
</xsl:call-template>
</xsl:if>
If anyone could push me in the right direction I'd very much appreciate it. if more info is needed let me know. The actual template "thecomment" is simply taking the comment passed to it and formatting it the way I'd like.
Rather than using an xsl:for-each and then a call to a named template, you could consider combining the two into one xsl:apply-templates call. Firstly, you would select the comments with a ResponseCommentID attribute of 0.
<xsl:apply-templates
select="in:inputs/in:result[#name='XML_Comment']/root/Comments[#ResponseCommentID='0']" />
Then, you would have a template to match the Comments attribute, where you would output the comment details. You could then recursively get the response comments like so:
<xsl:apply-templates select="../Comments[#ResponseCommentID = current()/#CommentID]" />
This would just recursively call the same Comments template until there are no more reponses.
Here is the full XSLT in this case (I am outputting the comments as list items in HTML just as an example)
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:in="http://www.composite.net/ns/transformation/input/1.0" exclude-result-prefixes="in">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<ul>
<xsl:apply-templates select="in:inputs/in:result[#name='XML_Comment']/root/Comments[#ResponseCommentID='0']" />
</ul>
</xsl:template>
<xsl:template match="Comments">
<li>
<xsl:value-of select="#Comment" />
<xsl:if test="../Comments[#ResponseCommentID = current()/#CommentID]">
<ul>
<xsl:apply-templates select="../Comments[#ResponseCommentID = current()/#CommentID]" />
</ul>
</xsl:if>
</li>
</xsl:template>
</xsl:stylesheet>
This gives the following output
<ul>
<li>test comment!!!!
<ul>
<li>my response
<ul>
<li>I don't agree with Norman. Terrible response.</li>
</ul>
</li>
<li>I've got something to say!</li>
</ul>
</li>
<li>test comment2!!!!</li>
<li>Not impressed...
<ul>
<li>I'm impressed.</li>
</ul>
</li>
<li>blah blah blah.
<ul>
<li>this is a response to blah blah blah.</li>
</ul>
</li>
<li>dfsfs</li>
</ul>
However, it would be more efficient to use an xsl:key here to look up the responses to comments:
<xsl:key name="Comments" match="Comments" use="#ResponseCommentID" />
Then to get the top-level comments you would do this:
<xsl:apply-templates select="key('Comments', '0')" />
And to get the responses to a given comment in your matching template, you would do this
<xsl:apply-templates select="key('Comments', #CommentID)" />
The following XSLT also gives the same results
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:in="http://www.composite.net/ns/transformation/input/1.0" exclude-result-prefixes="in">
<xsl:output method="xml" indent="yes"/>
<xsl:key name="Comments" match="Comments" use="#ResponseCommentID" />
<xsl:template match="/">
<ul>
<xsl:apply-templates select="key('Comments', '0')" />
</ul>
</xsl:template>
<xsl:template match="Comments">
<li>
<xsl:value-of select="#Comment" />
<xsl:if test="key('Comments', #CommentID)">
<ul>
<xsl:apply-templates select="key('Comments', #CommentID)" />
</ul>
</xsl:if>
</li>
</xsl:template>
</xsl:stylesheet>
I think I figured it out. Here's what my XLST looks like now. It will go thru all comments, but only if it's the first post (#ResponseCommentID = 0).
<xsl:for-each select="$root/Comments">
<xsl:if test="#ResponseCommentID = 0 and #CommentID != $root/Comments/#ResponseCommentID">
<!-- call the template to first plot the comment down -->
<xsl:call-template name="thecomment">
<xsl:with-param name="CommentID"><xsl:value-of select="#CommentID" /></xsl:with-param>
<xsl:with-param name="ResponseCommentID"><xsl:value-of select="#ResponseCommentID" /></xsl:with-param>
</xsl:call-template>
</xsl:if>
</xsl:for-each>
This is the recursive part at the end. It looks at all the comments, and calls the template for each #ResponseCommentID attribute that is equal to the current #CommentID.
<xsl:for-each select="$root/Comments[#ResponseCommentID = current()/#CommentID]">
<xsl:call-template name="thecomment">
<xsl:with-param name="CommentID"><xsl:value-of select="#CommentID" /></xsl:with-param>
<xsl:with-param name="ResponseCommentID"><xsl:value-of select="#ResponseCommentID" /></xsl:with-param>
</xsl:call-template>
</xsl:for-each>
Still don't understand it fully (I keep having to replay the sequence of events in my head), but I believe this works. :)