Xml 如果有URL参数,则显示单个条目,否则显示所有视频-Symphony CMS
我一直在研究Symphony,虽然我学习速度很慢,但我已经创建了一些基本网站。我正在努力解决的一件事是,如果有url参数,我希望我的主页模板(home.xsl)显示一个模板,如果参数为空,则只显示另一个模板Xml 如果有URL参数,则显示单个条目,否则显示所有视频-Symphony CMS,xml,xslt,url-parameters,symphony-cms,Xml,Xslt,Url Parameters,Symphony Cms,我一直在研究Symphony,虽然我学习速度很慢,但我已经创建了一些基本网站。我正在努力解决的一件事是,如果有url参数,我希望我的主页模板(home.xsl)显示一个模板,如果参数为空,则只显示另一个模板 <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml"
doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
omit-xml-declaration="yes"
encoding="UTF-8"
indent="yes" />
<xsl:template match="/">
<html>
<head>
<title>Homepage</title>
</head>
<body>
<h2>Videos</h2>
<ul>
<xsl:apply-templates select="/data/videos/entry"/>
</ul>
</body>
</html>
</xsl:template>
<xsl:template match="videos/entry/single">
<div class="video"><xsl:value-of select="greeting-text"/></div>
</xsl:template>
<xsl:template match="videos/entry">
<li><xsl:value-of select="greeting-text"/></li>
</xsl:template>
</xsl:stylesheet>
主页
视频
例如,在上面的代码(改编自“Hello World!”交响乐教程)中,有一个template match=“videos/entry/single”
和template match=“videos/entry”
。如果定义了URL参数(例如,我正在加载website.com/parameter),我希望显示第一个模板,它将显示“parameter”视频,如果没有定义参数,它将显示所有视频,即第二个模板
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml"
doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
omit-xml-declaration="yes"
encoding="UTF-8"
indent="yes" />
<xsl:template match="/">
<html>
<head>
<title>Homepage</title>
</head>
<body>
<h2>Videos</h2>
<ul>
<xsl:apply-templates select="/data/videos/entry"/>
</ul>
</body>
</html>
</xsl:template>
<xsl:template match="videos/entry/single">
<div class="video"><xsl:value-of select="greeting-text"/></div>
</xsl:template>
<xsl:template match="videos/entry">
<li><xsl:value-of select="greeting-text"/></li>
</xsl:template>
</xsl:stylesheet>
我真的很难解释事情,尤其是当我不完全了解技术的时候,所以请原谅我在写作中的任何愚蠢之处,如果必要的话,我很乐意解释更多 是否已将URL参数添加到模板所在的页面?您是否为单个视频添加了一个数据源,为多个视频添加了一个数据源?然后需要在页面上使用URL参数来确定要使用的代码块
- 关于页面:
- 关于URL参数:
- 关于数据源:
{$id}
)。如果未设置“id”,则不会返回任何结果<xsl:template match="/">
<html>
<head>
<title>Homepage</title>
</head>
<body>
<!-- this is the XSL version of an if/else
(basically check if URL Parameter 'id' is nothing,
display list, otherwise, display video by the 'id' provided) -->
<xsl:when test="not($id)">
<h2>Videos</h2>
<ul>
<xsl:apply-templates select="/data/videos/entry"/>
</ul>
</xsl:when>
<!-- here is where we tell it which template to use if
we do have a video id in the URL. We reference the second
datasource (single-video) in this case -->
<xsl:otherwise>
<xsl:apply-templates select="/data/single-video/entry"/>
</xsl:otherwise>
</body>
</html>
</xsl:template>
<!-- single video layout -->
<xsl:template match="single-video/entry">
<div class="video"><xsl:value-of select="greeting-text"/></div>
</xsl:template>
<!-- all videos layout -->
<xsl:template match="videos/entry">
<li><xsl:value-of select="greeting-text"/></li>
</xsl:template>
主页
视频
我希望这有帮助。Symphony需要一点时间来适应,但一旦你开始看到所有的片段是如何组合在一起的,它就真的有意义了。啊,我想我没有两个数据源是错的,我想我可以从所有数据源中只抓取一个视频,但一切都以你的方式变得更有意义。我只是在火车上旅行,所以我会在回家后更新并尝试一下:)在这个简单的例子中,我认为您可以只使用一个数据源和一些XPATH从列表中选择正确的视频,但我的答案更具可伸缩性,并且我认为这更好地解释了Symphony的结构方式。另外,通过这种方式,您可以添加Conditionalizer扩展,只运行对所需数据源的查询,而不是提取您不需要的视频信息,然后在模板中对其进行排序。但是如果您查看XML代码,您将看到两个数据源都有所有条目:单个视频和包含所有视频的列表,这意味着您的XML文件处理将花费与加载完整视频列表相同的时间来加载单个视频。我错了吗?有办法解决这个问题吗?