Question

I am trying to show articles from specific categories on my homepage.

xml removed.

Note: The category I need to fetch from is id=38. Which is showing but possibly by chance as it is included in the current articles.

I have fixed this problem, using a solution I found here. It was simple enough. My datasource was filtering categories as {$ds-categories}. I changed that to just 38 and it worked perfectly. Knew it would be something simple.

There's my home page doing this, which outputs blank divs in place of what should show:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:import href="../utilities/master.xsl"/>
<xsl:import href="../utilities/get-article.xsl"/>
<xsl:import href="../utilities/pagination.xsl"/>
<xsl:import href="../utilities/get-notes.xsl"/>
<xsl:import href="../utilities/get-comments.xsl"/>
<xsl:template match="data">
<div id="content" class="container">
        <div id="content">
          <div class="col content">
            <div class="col span1">
              <h4 class="n4">Recent entries</h4>
            </div>
          </div>
    <xsl:apply-templates select="homepage-articles/entry" mode="short"/>
    <xsl:apply-templates select="homepage-updates/entry" mode="updates"/>
                  </div>
        <div id="sidebar" class="col last">
            <xsl:call-template name="contact"/>
              <xsl:call-template name="social"/>
            <xsl:call-template name="category"/>
            <xsl:call-template name="tag"/>
            <xsl:call-template name="external-links"/>
        </div>
            </div>
</xsl:template>
</xsl:stylesheet>

Then my get-article template looks something like this:

  <xsl:template match="entry" mode="updates">
<div>
  <xsl:for-each select="entry[@handle = updates]">
            <div class="post-meta">
              <span><xsl:call-template name="format-date">
                    <xsl:with-param name="date" select="date"/>
                    <xsl:with-param name="format" select="'D M'"/>
                </xsl:call-template></span>
              <span id="year"><xsl:call-template name="format-date">
                <xsl:with-param name="date" select="date"/>
                    <xsl:with-param name="format" select="'Y'"/>
              </xsl:call-template></span>
                <ul>
                    <li>
                        <xsl:text>Tagged as: </xsl:text>
                        <xsl:for-each select="tags/item">
                            <a href="{$root}/archive/tag/{@handle}"><xsl:value-of select="."/></a>
                            <xsl:if test="position() != last()">, </xsl:if>
                        </xsl:for-each>
                    </li>
                    <li><a href="{$root}/post/{title/@handle}#comments"><xsl:value-of select="@comments"/> comment<xsl:if test="@comments != 1">s</xsl:if></a></li>
                </ul>
            </div>
            <div class="post-content last span-7">
                <h3><a href="{$root}/post/{title/@handle}"><xsl:value-of select="title"/></a></h3>
                <xsl:apply-templates select="body/*[position() &lt; 3]" mode="html"/>
                        <xsl:call-template name="get-images" />
              <p style="float: right; clear: both;"><a href="{$root}/post/{title/@handle}" title="Read {title}">Read the full article</a></p>
            </div>
    </xsl:for-each>
        </div>
    </xsl:template>

Thanks for the help! It definitely help me avoid bumping into further problems once I did solve this.

Was it helpful?

Solution

In your first template, you have an xsl:apply-templates

<xsl:apply-templates select="homepage-updates/entry" mode="updates"/>

You also has the template that matches this

<xsl:template match="entry" mode="updates">

So far, so good. But within this "entry" template, you then do this

<xsl:for-each select="entry[@handle = updates]">

This is looking for an entry element that is a child of the current entry element you are matching, or which there are none in your XML.

Try changing the template match to match the parent element instead:

<xsl:template match="homepage-updates" mode="updates">

And then change the xsl:apply-templates accordingly

<xsl:apply-templates select="homepage-updates" mode="updates"/>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top