[英]XSLT transforming generic nodes to specific nodes
我一直在努力對具有相同節點名稱並且需要在特定節點中拆分的文檔執行轉換。 在視覺上,您可以說這是將行轉換為列。 這是我的源文件:
<?xml version="1.0" encoding="UTF-8"?>
<Document>
<Car>
<Element>
<Question>Brand</Question>
<Answer>Ford</Answer>
</Element>
<Element>
<Question>Year</Question>
<Answer>1995</Answer>
</Element>
</Car>
<Car>
<Element>
<Question>Brand</Question>
<Answer>Hummer</Answer>
</Element>
<Element>
<Question>Year</Question>
<Answer>1990</Answer>
</Element>
</Car>
</Document>
我需要的是以下結果:
<Document>
<Car>
<Brand>Ford</Brand>
<Year>1995</Year>
</Car>
<Car>
<Brand>Hummer</Brand>
<Year>1990</Year>
</Car>
</Document>
有誰能夠幫助我?
好吧,這相當瑣碎,我不知道您為什么要為此苦苦掙扎:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/>
<xsl:template match="/Document">
<Document>
<xsl:for-each select="Car">
<Car>
<xsl:for-each select="Element">
<xsl:element name="{Question}">
<xsl:value-of select="Answer" />
</xsl:element>
</xsl:for-each>
</Car>
</xsl:for-each>
</Document>
</xsl:template>
</xsl:stylesheet>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.