下面沒有子節點的輸入XML,我有獲取父節點,如果在XSLT
<InputAnimationConfigurationSchema>
<ConfigurationEffects>
<AEffect Id="1" DisplayName="A Effect">
</WipeEffect>
<BEffect Id="2" DisplayName="B Effect">
</FadeEffect>
<CEffect Id="3" DisplayName="C Effect">
</ConfigurationEffects>
<ConfigurationMappings>
<ConfigurationMap>
<Widget Type="All" Include="true" NeedsMandatoryEffectConfiguration="true"/>
<Trigger Type="Show" />
<ConfigurationEffects>
<Effect>1</Effect>
<Effect>2</Effect>
<Effect>3</Effect>
<Effect>9</Effect>
</ConfigurationEffects>
</ConfigurationMap>
<ConfigurationMap>
<Widget Type="All" Include="true" NeedsMandatoryEffectConfiguration="true"/>
<Trigger Type="Hide" />
<ConfigurationEffects>
<Effect>1</Effect>
<Effect>2</Effect>
<Effect>3</Effect>
<Effect>9</Effect>
</ConfigurationEffects>
</ConfigurationMap>
<ConfigurationMap>
<Widget Type="PIGWidget" Include="false" NeedsMandatoryEffectConfiguration="true"/>
</ConfigurationMap>
<ConfigurationMap>
<Widget Type="PlaceHolder" Include="false" NeedsMandatoryEffectConfiguration="true"/>
</ConfigurationMap>
</ConfigurationMappings>
</InputAnimationConfigurationSchema>
我漸漸在下面的格式輸出:
All Show A Effect
--------------------------
All Show C Effect
--------------------------
All Show F Effect
-------------------------
All Show I Effect
----------------------------
All Hide A Effect
---------------------------
All Hide C Effect
--------------------------
現在的問題我面臨的是,如果沒有子節點可用於父節點,那麼該節點沒有得到打印,但我需要顯示小部件的佔位符和pigwidget也
我想在下面的輸出墊:
All Show A Effect
--------------------------
All Show C Effect
--------------------------
All Show F Effect
-------------------------
All Show I Effect
----------------------------
All Hide A Effect
---------------------------
All Hide C Effect
--------------------------
placeholder
---------------------------
pigwidget
---------------------------
上面我寫的XSL是這樣的:
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:key name="effectLookup" match="/InputAnimationConfigurationSchema/ConfigurationEffects/*" use="@Id" />
<xsl:template match="/">
<html>
<body>
<h2></h2>
<table border="1">
<tr bgcolor="#9acd32">
<th>Widget</th>
<th>Trigger</th>
<th>effects</th>
</tr>
<xsl:for-each select="/InputAnimationConfigurationSchema/ConfigurationMappings/ConfigurationMap">
<xsl:variable name="widgetType">
<xsl:value-of select="Widget/@Type"/>
</xsl:variable>
<xsl:variable name="triggerType">
<xsl:value-of select="Trigger/@Type"/>
</xsl:variable>
<xsl:for-each select="ConfigurationEffects/Effect">
<xsl:variable name="effectId">
<xsl:value-of select="./text()"/>
</xsl:variable>
<tr>
<td>
<xsl:value-of select="$widgetType"/>
</td>
<td>
<xsl:value-of select="$triggerType"/>
</td>
<td>
<xsl:value-of select="key('effectLookup', $effectId)/@DisplayName" />
</td>
</tr>
</xsl:for-each>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
請指導我如何來達到同樣的?
@ stuartLC - 這是你的代碼,我複製..需要更多的幫助,以顯示父節點,如果沒有子節點 –