Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xml 按类别筛选文章_Xml_Xslt_Xpath_Symphony Cms - Fatal编程技术网

Xml 按类别筛选文章

Xml 按类别筛选文章,xml,xslt,xpath,symphony-cms,Xml,Xslt,Xpath,Symphony Cms,我试图在我的主页上显示特定类别的文章 删除xml 注意:我需要从中获取的类别id=38。这是显示,但可能是偶然的,因为它是包括在当前的文章 我已经修复了这个问题,使用了。 这很简单。我的数据源将类别筛选为{$ds categories}。我把它改为38,它工作得很好。我知道这很简单 我的主页就是这样做的,它输出空白div来代替应该显示的内容: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0"

我试图在我的主页上显示特定类别的文章

删除xml

注意:我需要从中获取的类别id=38。这是显示,但可能是偶然的,因为它是包括在当前的文章

我已经修复了这个问题,使用了。 这很简单。我的数据源将类别筛选为{$ds categories}。我把它改为38,它工作得很好。我知道这很简单

我的主页就是这样做的,它输出空白div来代替应该显示的内容:

<?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>

最近的条目
然后,我的获取文章模板如下所示:

  <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>

  • 标记为: ,


谢谢你的帮助!一旦我解决了这个问题,它肯定会帮助我避免遇到进一步的问题。

在您的第一个模板中,您有一个xsl:apply-templates

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

您还有与此匹配的模板

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

到目前为止,一切顺利。但是在这个“条目”模板中,您可以这样做

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

这是在寻找一个条目元素,该元素是当前匹配的条目元素的子元素,或者XML中没有该元素

请尝试更改模板匹配以匹配父元素:

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

然后相应地更改xsl:apply-templates

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


您能否提供原始XML、您一直使用的XSLT以及预期结果的示例?@NickG我已更新了主要注释以显示所有相关信息。我觉得这可能是我的数据源的一个问题,这是目前从像主页文章一样的文章部分获取的。如果有帮助,我可以提供此设置的屏幕截图。若要检查您的数据源及其包含的条目,请在登录Symphony CMS时在URL末尾添加
?debug
。@DavidOliver是的,据我所知,我的数据源与主页文章一样工作,并获取所有文章。当我真正想要的是一个类似于归档页面的页面内类别视图时。没有文章出现在页面上(但在xml中)这一事实告诉我xslt有问题。我会继续摆弄,如果我弄明白了,就把发生的事情发出去。@DavidOliver谢谢!我在谷歌上搜索了几个小时后就解决了这个问题。一切都很好,只是我的数据源过滤不好。那似乎不起作用。它刚刚删除了我的空白div…修改我的模板并在页面中为每一条语句添加相应的内容行吗?嗯。。。如果看不到完整的XML或XSLT版本,就很难给出准确的答案(例如,目前XSLT正在entry元素上查找名为handle的属性,但不存在这样的属性)。理想情况下,您可以尝试将XML和XSLT缩减到再现问题的绝对最小值,然后在问题中说明这一点。您可能会发现,剥离这些内容有助于您自己确定实际问题。谢谢好吧我修好了。我所要做的就是改变我的数据源。我有类别输出整个选择。刚把它改成38,更新类别的id。还摆脱了为每一个东西,它的工作完美!谢谢你的帮助。