我正在使用JavaFX應用程序,並且我有一個xml文件,我想將其轉換爲html。 xml文件具有一些具有相同屬性名稱但子名稱不同的元素。我想根據具有相同屬性值的父元素對子元素進行分組。xsl樣式表:獲取具有相同屬性值的父元素的子元素
的xml文件看起來是這樣的:
<?xml version="1.0" encoding="UTF-8" ?>
<application>
<workflow name="Model Structure">
<name>Model Structure</name>
<source>Model data</source>
<type>Aleatory</type>
<condition>independet</condition>
<distribution>None</distribution>
<assumptions>onsdn</assumptions>
</workflow>
<workflow name="Model Structure">
<name>Model Structure</name>
<source>Poor data</source>
<type>Aleatory</type>
<condition>independet</condition>
<distribution>GLC</distribution>
<assumptions>nsisodsd</assumptions>
</workflow>
</application
我所要的輸出是這樣的:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<body>
<h3>Model Structure</h3>
<ol type="1">
<li>
<p>Source: Model data</p>
<p>Type: Aleatory</p>
<p>Conditions: Independent</p>
<p>Distribution: GLV</p>
<p>Assumptions: sibsdisbdibs</p>
</li>
<li>
<p>Source: Poor data</p>
<p>Type: Epistemic with probabilities</p>
<p>Conditions: Independent</p>
<p>Distribution: GLV</p>
<p>Assumptions: sibsdisbdibs</p>
</li>
</ol>
<h3>Boundary Conditions</h3>
<ol type="1">
<li>
<p>Source: Parametric conditions</p>
<p>Type: Aleatory</p>
<p>Conditions: Independent</p>
<p>Distribution: None</p>
<p>Assumptions: blablabla</p>
</li>
<li>
<p>Source: Some boundaries</p>
<p>Type: Epistemic with probabilities</p>
<p>Conditions: Independent</p>
<p>Distribution: GLV</p>
<p>Assumptions: sibsdisbdibs</p>
</li>
</ol>
</body>
</html>
我我在xsl樣式表中爲每個語句使用了一個,但是我找不到一個很好的方法來檢查迭代中下一個元素的值,並避免將它打印在html文件中。
<xsl:value-of select="@*" />
<xsl:for-each select="application/workflow">
<xsl:variable name="tempname">
<xsl:value-of select="name" /></xsl:variable>
<h3> <xsl:value-of select="@name"/> </h3>
<ol type="1">
<ul>
<p>Source:
<xsl:value-of select="source" />
</p>
<p>Type:
<xsl:value-of select="type" />
</p>
<p>Conditions:
<xsl:value-of select="condition" />
</p>
<p>Distribution:
<xsl:value-of select="distribution" />
</p>
<p>Assumptions:
<xsl:value-of select="assumptions" />
</p>
</ul>
</ol>
</xsl:for-each>
你可以使用XSLT 2.0? - P.S.有多個組的例子會很有用。 –
我編輯了我想要顯示兩個組的結果。我嘗試使用元素與臨時變量,但xsl不允許更改變量的值。 –
您是否理解使用XSLT 2.0的問題? –