我想使用xslt將下面的xml轉換爲html。XSLT foreach複雜條件
horder - 表示元素
vorder的行位置 - 表示元素的列位置
行 - 總無。列中存在的行數
列 - 總數沒有。的
<Page>
<Sections>
<Section id="parent_hdr_sec" haschild="y" layout="hbox" rows="2" columns="1" horder="1" vorder="1">
<Sections>
<Section id="plan_hdr" layout="vbox" rows="1" columns="6" horder="1" vorder="1" />
<Section id="plan_hdr_dtl" layout="vbox" rows="1" columns="5" horder="2" vorder="1" />
</Sections>
</Section>
<Section id="splitter_sec" haschild="y" layout="vbox" rows="1" columns="2" horder="2" vorder="1">
<Sections>
<Section id="parent_left_sec" haschild="y" layout="hbox" rows="4" columns="1" horder="1" vorder="1" />
<Section id="parent_right_sec" haschild="y" layout="hbox" rows="7" columns="1" horder="1" vorder="2" />
<Section id="parent_left_sec_1" layout="hbox" rows="1" columns="6" horder="2" vorder="1" />
<Section id="parent_right_sec_1" layout="hbox" rows="1" columns="5" horder="2" vorder="2" />
</Sections>
</Section>
</Sections>
</Page>
需要HTML輸出出現在元素中列:
<html>
<body>
<table>
<tr>
<td id="parent_hdr_sec">
<table>
<tr>
<td id="plan_hdr"></td>
</tr>
<tr>
<td id="plan_hdr_dtl"></td>
</tr>
</table>
</td>
</tr>
<tr>
<td id="splitter_sec">
<table>
<tr>
<td id="parent_left_sec"></td>
<td id="parent_right_sec"></td>
</tr>
<tr>
<td id="parent_left_sec_1"></td>
<td id="parent_right_sec_1"></td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
請幫助我建立XSLT對上述一個...需要建議對此..
我的XSLT:
<xsl:template match="/">
<html>
<body>
<table>
<xsl:for-each select="Page/Sections/Section">
<tr>
<td id="{@id}">
<table>
<xsl:variable name="Rows" select="@rows"/>
<xsl:variable name="Columns" select="@columns"/>
<xsl:variable name="Layout" select="@layout"/>
<xsl:if test="$Layout = 'hbox'">
<xsl:for-each select="Sections/Section[$Rows >= position()]">
<tr>
<td id="{@id}">
</td>
</tr>
</xsl:for-each>
</xsl:if>
<xsl:if test="$Layout = 'vbox'">
<tr>
<xsl:for-each select="Sections/Section[$Columns >= position()]">
<td id="{@id}">
</td>
</xsl:for-each>
</tr>
</xsl:if>
</table>
</td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
我用上面的XSLT使用foreach條件並得到像這樣的輸出
我的輸出:
<?xml version="1.0" encoding="utf-8"?>
<html>
<body>
<table>
<tr>
<td id="parent_hdr_sec">
<table>
<tr>
<td id="plan_hdr" />
</tr>
<tr>
<td id="plan_hdr_dtl" />
</tr>
</table>
</td>
</tr>
<tr>
<td id="splitter_sec">
<table>
<tr>
<td id="parent_left_sec" />
<td id="parent_right_sec" />
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
Downvoting,因爲你沒有解釋你卡在哪裏。你只是要求人們爲你寫代碼,而不是解釋你爲什麼不能自己寫。 –
@MichaelKay Im new to XSLT so so stucked here ... Sorry for not posting my XSLT code at ... – Hari