0
我有這樣的XML,並用XSLT問題變換:XSL:獲取XML元素到另一個節點
<start>
<row>
<xxx Caption="School1"></xxx>
<yyy Caption="Subject1"></yyy>
<zzz></zzz>
</row>
<row>
<xxx Caption="School2"></xxx>
<yyy Caption="Subject2"></yyy>
<zzz></zzz>
</row>
</start>
的XSL變換是這樣的:
<xsl:stylesheet>
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<schools>
<xsl:apply-templates select="//row/*" />
</schools>
</xsl:template>
<xsl:template match="//row/*">
<school>
<xsl:if test="name()='xxx'">
<name>
<xsl:value-of select="@Caption"/>
</name>
</xsl:if>
<xsl:if test="name()='yyy'">
<subject>
<xsl:value-of select="@Caption"/>
</subject>
</xsl:if>
</school>
</xsl:template>
</xsl:stylesheet>
XSL轉換給這樣的結果,這不正是我希望它是:
<schools>
<school>
<name>School1</name>
</school>
<school>
<subject>Subject1</subject>
</school>
<school />
<school>
<name>School2</name>
</school>
<school>
<subject>Subject2</subject>
</school>
<school />
</schools>
我想要的結果是這樣的:
<schools>
<school>
<name>School1</name>
<subject>Subject1</subject>
</school>
<school>
<name>School2</name>
<subject>Subject2</subject>
</school>
</schools>
名稱和主題元素應該在同一個學校元素中。
請幫助我獲得更好的解決方案。