我想要改造這個XMLXSLT轉換每個複雜條件
XML:
<Page>
<Sections>
<Section id="parent_hdr_sec" rows="2" columns="1">
<Sections>
<Section id="plan_hdr" rows="0" columns="0" />
<Section id="plan_hdr_dtl" rows="0" columns="0" />
</Sections>
</Section>
<Section id="splitter_sec" rows="1" columns="2">
<Sections>
<Section id="parent_left_sec" rows="4" columns="1">
</Section>
<Section id="parent_right_sec" rows="7" columns="1">
</Section>
</Sections>
</Section>
</Sections>
</Page>
XSLT:
<xsl:template match="/">
<html>
<body>
<table>
<xsl:for-each select="Page/Sections/Section">
<tr>
<td>
<xsl:attribute name="id">
<xsl:value-of select="@id"/>
</xsl:attribute>
<table>
<xsl:variable name="Rows" select="@rows"/>
<xsl:variable name="Columns" select="@columns"/>
<xsl:for-each select="(//Section/Sections/Section)[$Rows >= position()]">
<tr>
<xsl:for-each select="(//Section/Sections/Section)[$Columns >= position()]">
<td>
<xsl:attribute name="id">
<xsl:value-of select="@id"/>
</xsl:attribute>
</td>
</xsl:for-each>
</tr>
</xsl:for-each>
</table>
</td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
我的輸出:
<html>
<body>
<table>
<tr>
<td id="parent_hdr_sec">
<table>
<tr>
<td id="plan_hdr"></td>
</tr>
<tr>
<td id="plan_hdr"></td>
</tr>
</table>
</td>
</tr>
<tr>
<td id="splitter_sec">
<table>
<tr>
<td id="plan_hdr"></td>
<td id="plan_hdr_dtl"></td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
正確的輸出:
'ID' 變量值在我的輸出錯誤更新。
我需要輸出這樣的下面,
<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>
</table>
</td>
</tr>
</table>
</body>
</html>
我想XSLT每個條件得到上面的輸出。
誰能幫我解決這個問題..
感謝您的回覆。我正在輸出這樣,如果使用上述的一個 – Hari
@Hari請不要張貼在評論的代碼,它是相當難以理解。 –