好撒克遜9或任何XSLT 2.0處理器,可以生成多個結果文檔與一個樣式表,作爲連接兩個文件有什麼困難這一點,你只會使用HTML a
元素與鏈接到其他文檔的href
屬性。
如果您需要某個特定數據的幫助,請發佈一個小而具有代表性的XML輸入示例,以及您想要創建的HTML。
[編輯]
假設你有一對夫婦的a:file
要素的輸入文檔,您要創建一個主HTML文件,列出所有a:names
連接到單獨的文件列表,你可以解決如下的詳細信息:
<xsl:template match="/">
<xsl:apply-templates select="//a:file" mode="doc"/>
<html>
<head>
<title>Example</title>
</head>
<body>
<h1>Data list</h1>
<ul>
<xsl:apply-templates select="//a:file"/>
</ul>
</body>
</html>
</xsl:template>
<xsl:template match="a:file">
<li>
<a href="{a:id}.html">
<xsl:value-of select="a:name"/>
</a>
</li>
</xsl:template>
<xsl:template match="a:file" mode="doc">
<xsl:result-document href="{a:id}.html">
<html>
<head>
<title>Details of <xsl:value-of select="a:name"/></title>
</head>
<body>
<table>
<thead>
<tr>
<xsl:apply-templates mode="thead"/>
</tr>
</thead>
<tbody>
<tr>
<xsl:apply-templates mode="doc"/>
</tr>
</tbody>
</table>
</body>
</html>
</xsl:result-document>
</xsl:template>
<xsl:template match="a:file/*" mode="doc">
<td>
<xsl:value-of select="."/>
</td>
</xsl:template>
<xsl:template match="a:file/*" mode="thead">
<th>
<xsl:value-of select="local-name()"/>
</th>
</xsl:template>
未經測試,但應該給你一個想法。如果你需要更多的幫助,那麼請顯示你的輸入和想要的輸出的更多細節,我不得不補充主要HTML結果(在那裏使用一個列表)和細節文件(在那裏使用一個表格)的格式。
[編輯2] 假設完整輸入樣本是
<a:files xmlns:a="http://example.com/a">
<a:file>
<a:id>33</a:id>
<a:name>hello</a:name>
<a:school>mumbai public</a:school>
<a:marks>80</a:marks>
</a:file>
</a:files>
和完整的樣式表樣品是
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:a="http://example.com/a"
exclude-result-prefixes="a"
version="2.0">
<xsl:template match="/">
<xsl:apply-templates select="//a:file" mode="doc"/>
<html>
<head>
<title>Example</title>
</head>
<body>
<h1>Data list</h1>
<ul>
<xsl:apply-templates select="//a:file"/>
</ul>
</body>
</html>
</xsl:template>
<xsl:template match="a:file">
<li>
<a href="{a:id}.html">
<xsl:value-of select="a:name"/>
</a>
</li>
</xsl:template>
<xsl:template match="a:file" mode="doc">
<xsl:result-document href="{a:id}.html">
<html>
<head>
<title>Details of <xsl:value-of select="a:name"/></title>
</head>
<body>
<table>
<thead>
<tr>
<xsl:apply-templates mode="thead"/>
</tr>
</thead>
<tbody>
<tr>
<xsl:apply-templates mode="doc"/>
</tr>
</tbody>
</table>
</body>
</html>
</xsl:result-document>
</xsl:template>
<xsl:template match="a:file/*" mode="doc">
<td>
<xsl:value-of select="."/>
</td>
</xsl:template>
<xsl:template match="a:file/*" mode="thead">
<th>
<xsl:value-of select="local-name()"/>
</th>
</xsl:template>
</xsl:stylesheet>
然後當我使用撒克遜9.4 HE從命令行做例如java -jar saxon9he.jar input.xml sheet.xsl -o:result.html
我得到兩個結果文件,主菜是result.html
的,另一個是33.html
看起來如下:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Example</title>
</head>
<body>
<h1>Data list</h1>
<ul>
<li><a href="33.html">hello</a></li>
</ul>
</body>
</html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Details of hello</title>
</head>
<body>
<table>
<thead>
<tr>
<th>id</th>
<th>name</th>
<th>school</th>
<th>marks</th>
</tr>
</thead>
<tbody>
<tr>
<td>33</td>
<td>hello</td>
<td>mumbai public</td>
<td>80</td>
</tr>
</tbody>
</table>
</body>
</html>
所以這對我來說,工作正常,都儘可能的文件數量而言,以及用於瀏覽器內部的鏈接工作。
是的我做了同樣的使用a和href,但如何顯示在第二個html上的特定記錄的信息。假設我點擊了一個名爲'details'的鏈接,所以當我點擊詳細信息時,我只能得到一個特定的信息,而不是一切。 – user1402867
我編輯我的問題,並放置一個示例XML輸入。在這一頁上我顯示了所有的名字,當我點擊名字時,我應該被重定向到另一個顯示完整細節的頁面。 – user1402867
我編輯了我的答案並添加了一個代碼示例,顯示如何處理該代碼示例,它將生成主要轉換結果作爲顯示所有項目的HTML文檔,然後鏈接到顯示單個項目詳細信息的更多結果文檔。 –