Search

Hello,

this is very much a beginner's question, I guess:

I have created a blog. Each page displays 10 posts. This already works easily. Now I want to add to every post all its comments. These comments are in another section and every comment is linked to a post by a Select Box Link field.

I only manage to first list 10 posts in one block and after them all comments in one block.

I am looking forward to you help, thank you very much+ Moritz

What you would need to do; is use the ds-param output from the first one; so you can use it in the comments datasource (I think you got this bit right)

Then in your XSLT after each article; you should do something like

<xsl:apply-templates select='/data/comments/entry[/article/@id = $article-id]'/>

make sure you set $article-id for every article and create a template to display the comments and you'll be fine.

Thank you very much, gunglien! I will try your hint this evening and then report how it went.

Sure you're more then welcome, the order has to be done via XSLT if you have problems post your xml and xslt and will help you out :)

I am afraid I haven't managed to succeed yet. I'd like to make use of you offer to chek my xsl

  • datasources are nachrichten and kommentare
  • The param is named ds-nachrichten.system-id

I have uploaded the xml to http://pastie.org/private/l0hrkbri1r65yaw6f03a

I guess the mistake is in the apply template? I get all nachrichten (posts) but no kommentare (comments). By the way, is the concept you're showing me "data source chaining"? Thanks a lot!

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:include href="../utilities/master.xsl"/>


<xsl:template match="data">
    <xsl:apply-templates select="nachrichten/entry"/>
    <xsl:apply-templates select="/data/kommentare/entry[/nachricht/@id = $ds-nachrichten]"/>
</xsl:template>


<xsl:template match="nachrichten/entry">
    <h2><xsl:value-of select="ueberschrift"/></h2>
    <ul>
        <li><xsl:value-of select="datum"/></li>
        <li><xsl:value-of select="format"/></li>
        <li><xsl:value-of select="ueberschrift"/></li>
    </ul>
    <p><xsl:value-of select="nachricht"/></p>
    <img>
        <xsl:attribute name="src">/image/<xsl:value-of select="bild/filename"/></xsl:attribute>
        <xsl:attribute name="height">200</xsl:attribute>
    </img>
    <hr />
</xsl:template>

<xsl:template match="kommentare/entry">
    <xsl:value-of select="kommentar"/>
</xsl:template>

</xsl:stylesheet>

What that template does is outputs all the entries, then all the comments. What you need to do is in each article output its child comments. Try the below code and let me know how it goes.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:include href="../utilities/master.xsl"/>


<xsl:template match="data">
    <xsl:apply-templates select="nachrichten/entry"/>
</xsl:template>


<xsl:template match="nachrichten/entry">
    <h2><xsl:value-of select="ueberschrift"/></h2>
    <ul>
        <li><xsl:value-of select="datum"/></li>
        <li><xsl:value-of select="format"/></li>
        <li><xsl:value-of select="ueberschrift"/></li>
    </ul>
    <p><xsl:value-of select="nachricht"/></p>
    <img>
        <xsl:attribute name="src">/image/<xsl:value-of select="bild/filename"/></xsl:attribute>
        <xsl:attribute name="height">200</xsl:attribute>
    </img>
    <xsl:variable name='nachricht-id' select='@id'/>
    <xsl:apply-templates select="/data/kommentare/entry[/nachricht/@id = $nachricht-id]"/>
    <hr />
</xsl:template>

<xsl:template match="kommentare/entry">
    <xsl:value-of select="kommentar"/>
</xsl:template>
</xsl:stylesheet>

Hi gunglien,

thanks again for your help and quick reply. Your code does not work, unfortunately. I have tried another code now that does the job:

<xsl:for-each select="/data/kommentare/entry[nachricht/item/@id = current()/@id]">
    <xsl:value-of select="name"/> / <xsl:value-of select="kommentar"/>
</xsl:for-each>

However, I'd prefer your solution using a template. I have also tried your code with an added "entry" in the select path.

Any ideas?

hmm try putting your select with the apply-templates. So try

<xsl:apply-templates select="/data/kommentare/entry[/nachricht/item/@id = current()/@id]"/>

It should work. sorry was trying quickly and might have not checked the xml properly :)

Now it works, I only had to remove one slash:

<xsl:apply-templates select="/data/kommentare/entry[nachricht/item/@id = current()/@id]"/>

I appreciate your help a lot!

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details