首先,这里是情况。我正在使用一个公会托管站点,该站点允许您将URL输入到XSL文件和另一个XML输入。当你想要的所有XML都包含在一个文件中时,一切顺利。制作XSL样式表使用分页XML工作
我的问题是这样的Game Roster XML这是分页...看看接近该文件的底部,你会发现一个<page_links>
节,其中包含写在HTML链接到/xml?page=2
等寻呼机由于公会托管网站设置只处理一个XML页面,我无法访问其他XML页面。
所以,我只能想到两种解决方案,但我不知道如何开始
- 成立,结合了所有的XML页面转换成一个PHP页面,然后输出文件。然后,我可以在公会托管站点XSL处理器中使用此URL。
- 以某种方式组合XSL样式表中的所有XML文件。我在SO上找到了this question(我并不是很了解它,因为我不知道
document($pXml1)
在做什么),但我认为它不会起作用,因为页数会变化。我认为这可能是通过加载下一页,直到<members_to>
值等于<members_total>
。
还有其他想法吗?我不知道XSL或PHP,所以任何帮助与代码示例将不胜感激。
更新:我试着上面的方法2,这里是我遇到麻烦的XSLT片段。代码的第一页显示没有问题,但我遇到了这个xsl:if
,或者可能是document()
声明的问题。
更新#2:将文档更改为使用字符串& concat函数,但它仍然不起作用。
<xsl:template name="morepages">
<xsl:param name="page">1</xsl:param>
<xsl:param name="url">
<xsl:value-of select="concat(SuperGroup/profule_url,'/xml?page=')"/>
</xsl:param>
<xsl:if test="document(string(concat($url,$page)))/SuperGroup/members_to < document(string(concat($url,$page)))/SuperGroup/members_total">
<xsl:for-each select="document(string(concat($url,$page + 1)))/SuperGroup/members/members_node">
<xsl:call-template name="addrow" />
</xsl:for-each>
<!-- Increment page index-->
<xsl:call-template name="morepages">
<xsl:with-param name="page" select="$page + 1"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
更新#3:感谢您的伟大的开始拉克兰!但我试图用HTML输出。我有一个“addrow”模板和一个主模板,我不知道如何将它与您提供的XSL整合在一起。以下是我有:
<!-- add a member row -->
<xsl:template name="addrow">
<tr>
<td class="coName">
<xsl:element name="a">
<xsl:attribute name="target">
<xsl:text>_blank</xsl:text>
</xsl:attribute>
<xsl:attribute name="href">
<xsl:value-of select="profile_url"/>
</xsl:attribute>
<xsl:value-of select="pcname"/>
</xsl:element>
</td>
<xsl:element name="td">
<xsl:attribute name="class">
<xsl:text>coAccount</xsl:text>
</xsl:attribute>
<xsl:value-of select="pcaccount"/>
</xsl:element>
<td class="coLevel"><xsl:value-of select="ilevel"/></td>
<xsl:if test="irank!=''">
<td class="coRank">
<xsl:value-of select="irank"/>
</td>
</xsl:if>
<td class="coStatus"><xsl:value-of select="pcmapname"/></td>
</tr>
</xsl:template>
<!-- main template -->
<xsl:template match="/">
<div class="coGuildName">
<xsl:element name="img">
<xsl:attribute name="src">
<xsl:text>http://champions-online.com</xsl:text>
<xsl:value-of select="SuperGroup/guild_name_img"/>
</xsl:attribute>
</xsl:element>
</div>
<table width="100%" cellspacing="0" cellpadding="0" id="coRoster" align="center">
<thead>
<tr class="ForumCategoryHeader">
<th class="coName">Name</th>
<th class="coAccount">Account</th>
<th class="coLevel">Level</th>
<xsl:if test="SuperGroup/ranks!=''">
<th class="coRank">Rank</th>
</xsl:if>
<th class="coStatus">Status</th>
</tr>
</thead>
<tbody>
<xsl:for-each select="SuperGroup/members/members_node">
<xsl:call-template name="addrow" />
</xsl:for-each>
<!-- if less then total members shown, load next XML page -->
<xsl:if test="SuperGroup/members_to < SuperGroup/members_total">
<xsl:call-template name="morepages"/>
</xsl:if>
</tbody>
</table>
</xsl:template>
更新#4:我仍然坚持。这个XSL不会加载任何额外的XML页面。我曾尝试将SuperGroup[position()]
添加到SuperGroup
和members
模板中,但未成功。我也尝试将代码重新格式化为类似this post的东西,但仍然没有运气。我会很感激任何其他的想法。
我敢肯定你可以用XSLT递归地做到这一点。该例中的'document'函数调用'pxml1'变量中指定的uri。 – 2010-03-25 20:49:50
@Jweede:谢谢!这是我正在尝试的方法,但是我在上面的代码片段中遇到了问题。 – Mottie 2010-03-25 23:08:04