首先,這裏是情況。我正在使用一個公會託管站點,該站點允許您將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