我是很新的XSL和我得到了以下問題:XSLT - 與配對多次出現兩個節點的內容到一個輸出每次出現
有,有很多在這節點的XML文件。
<cruisecontrol>
...
<sysinfo>
<info/>
</sysinfo>
...
<vminfo>
<info/>
</vminfo>
...
<sysinfo>
<info/>
</sysinfo>
...
<vminfo>
<info/>
</vminfo>
...
<sysinfo>
<info/>
</sysinfo>
...
<vminfo>
<info/>
</vminfo>
...
</cruisecontrol>
'sysinfo'和'vminfo'節點出現多次,但在這個XML文件中的數量相同。現在我需要將此文件轉換爲HTML文件以顯示結果(巡航控件插件)。問題是,我想配對'sysinfo'和'vminfo'的內容。
我得到的只是......像這樣:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:template match="/">
<h1>System Information</h1>
<xsl:apply-templates select="//sysinfo"/>
<h1>VM Information</h1>
<xsl:apply-templates select="//vminfo"/>
</xsl:template>
<xsl:template match="sysinfo">
<xsl:apply-templates select="info"/>
</xsl:template>
<xsl:template match="vminfo">
<xsl:apply-templates select="info"/>
</xsl:template>
<xsl:template match="info">
<xsl:value-of select ="name(.)"/>
<xsl:value-of select="."/>
</xsl:template>
</xsl:stylesheet>
輸出看起來像:
System Information
<sysinfo1>
<info>
<sysinfo2>
<info>
VM Information
<vminfo1>
<info>
<vminfo2>
<info>
但我想要的是:
<sysinfo1>
<info>
<vminfo1>
<info>
<sysinfo2>
<info>
<vminfo2>
<info>
是否有可能,擺脫 'SYSINFO' 的 '信息' 和'vminfo'交替?
你的問題不清楚:'sysinfo'和'vminfo'節點是成對的嗎?或者他們在單獨的區塊?什麼是你想要的輸出?你的樣式表說「html」,但是它輸出文本(而不是你顯示的輸出)。請澄清。 –
'sysinfo'和'vminfo'都是'cruisecontrol'的childelement。它們都有多個外觀,並且總是相互依存(第一個'sysinfo'總是屬於第一個'vminfo',第二個'sysinfo'屬於第二個'vminfo'等等,但是它們可以被其他的childelement '巡航控制')。輸出將是HMTL,但是我從代碼中刪除了HTML部分以使其更短。 – Sarkkhan
「*他們都有多次出現,並且總是緊接着彼此*」這不能回答我的問題。請編輯您的示例,使其至少包含兩個。 –