Note that there are some explanatory texts on larger screens.

plurals
  1. POXSLT commenting system
    text
    copied!<p>I'm trying to build a commenting system with XSLT. Here's the XML input for comments already submitted:</p> <pre><code>&lt;in:inputs xmlns:in="http://www.composite.net/ns/transformation/input/1.0"&gt; &lt;!-- Input Parameter, XPath /in:inputs/in:param[@name='story_id'] --&gt; &lt;in:param name="story_id"&gt;182485599&lt;/in:param&gt; &lt;!-- Function Call Result (0 ms), XPath /in:inputs/in:result[@name='LoggedInWebUserID'] --&gt; &lt;in:result name="LoggedInWebUserID"&gt;233459&lt;/in:result&gt; &lt;!-- Function Call Result (9 ms), XPath /in:inputs/in:result[@name='XML_Comment']/root --&gt; &lt;in:result name="XML_Comment"&gt; &lt;root xmlns=""&gt; &lt;Comments CommentID="1" ResponseCommentID="0" WebUserID="123456" FULL_NAME="Osikhuemhe Abulume" Comment="test comment!!!!" DateSubmitted="Feb 20 2013 1:34PM"/&gt; &lt;Comments CommentID="2" ResponseCommentID="0" WebUserID="261337" FULL_NAME="Phillip Lowe" Comment="test comment2!!!!" DateSubmitted="Feb 20 2013 5:14PM"/&gt; &lt;Comments CommentID="3" ResponseCommentID="1" WebUserID="000007" FULL_NAME="Norman Abbott" Comment="my response" DateSubmitted="Feb 20 2013 5:14PM"/&gt; &lt;Comments CommentID="4" ResponseCommentID="0" WebUserID="233459" FULL_NAME="Tamara Failor" Comment="Not impressed..." DateSubmitted="Feb 20 2013 4:10PM"/&gt; &lt;Comments CommentID="5" ResponseCommentID="0" WebUserID="233459" FULL_NAME="Tamara Failor" Comment="blah blah blah. " DateSubmitted="Feb 20 2013 4:11PM"/&gt; &lt;Comments CommentID="6" ResponseCommentID="0" WebUserID="233459" FULL_NAME="Tamara Failor" Comment="dfsfs" DateSubmitted="Feb 20 2013 4:14PM"/&gt; &lt;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"/&gt; &lt;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"/&gt; &lt;Comments CommentID="9" ResponseCommentID="4" WebUserID="233459" FULL_NAME="Tamara Failor" Comment="I'm impressed." DateSubmitted="Feb 20 2013 5:43PM"/&gt; &lt;Comments CommentID="10" ResponseCommentID="1" WebUserID="233459" FULL_NAME="Tamara Failor" Comment="I've got something to say!" DateSubmitted="Feb 20 2013 6:34PM"/&gt; &lt;/root&gt; &lt;/in:result&gt; </code></pre> <p></p> <p>This should work like any other commenting system for news stories (see: <a href="http://www.npr.org/2013/02/20/172384724/when-a-bad-economy-means-working-forever" rel="nofollow">http://www.npr.org/2013/02/20/172384724/when-a-bad-economy-means-working-forever</a>)</p> <p>That is - new comments (ResponseCommentID = 0) would always be pushed to the left.</p> <p>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)</p> <p>There are two parts where I'm stuck. The first part is how each post should be called:</p> <pre><code> &lt;xsl:variable name="story_id" select="/in:inputs/in:param[@name='story_id']" /&gt; &lt;xsl:variable name="root" select="/in:inputs/in:result[@name='XML_Comment']/root" /&gt; &lt;xsl:for-each select="$root/Comments[@ResponseCommentID=0]"&gt; &lt;!-- call the template to plot the first comment down --&gt; &lt;xsl:call-template name="thecomment"&gt; &lt;xsl:with-param name="CommentID"&gt;&lt;xsl:value-of select="@CommentID" /&gt;&lt;/xsl:with-param&gt; &lt;xsl:with-param name="ResponseCommentID"&gt;&lt;xsl:value-of select="@ResponseCommentID" /&gt;&lt;/xsl:with-param&gt; &lt;/xsl:call-template&gt; &lt;!-- if the comment has any responses, put those underneath the root --&gt; &lt;xsl:for-each select="$root/Comments[current()/@CommentID = $root/Comments/@ResponseCommentID]"&gt; &lt;xsl:call-template name="thecomment"&gt; &lt;xsl:with-param name="CommentID"&gt;&lt;xsl:value-of select="@CommentID" /&gt;&lt;/xsl:with-param&gt; &lt;xsl:with-param name="ResponseCommentID"&gt;&lt;xsl:value-of select="@ResponseCommentID" /&gt;&lt;/xsl:with-param&gt; &lt;/xsl:call-template&gt; &lt;/xsl:for-each&gt; </code></pre> <p> </p> <p>The (also very wrong) ending recursion part of the template:</p> <pre><code> &lt;xsl:if test="@CommentID = $root/Comments/@ResponseCommentID"&gt; &lt;xsl:call-template name="thecomment"&gt; &lt;xsl:with-param name="CommentID"&gt;&lt;xsl:attribute name="value"&gt;&lt;xsl:value-of select="@CommentID[@CommentID = $root/Comments/@ResponseCommentID]" /&gt;&lt;/xsl:with-param&gt; &lt;xsl:with-param name="ResponseCommentID"&gt;&lt;xsl:attribute name="value"&gt;&lt;xsl:value-of select="@ResponseCommentID[@CommentID = $root/Comments/@ResponseCommentID]" /&gt;&lt;/xsl:with-param&gt; &lt;/xsl:call-template&gt; &lt;/xsl:if&gt; </code></pre> <p>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.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload