0
我想通過XML元素通過一個公共元素值對數據進行分組。 輸入XML結構爲:使用XSLT 2.0基於元素值和屬性對XML元素進行分組
<?xml version="1.0" encoding="utf-8"?>
<Data>
<output outputType="CORRECTION">
<row nodeName="ORDER_HEADER" tableName="ORDER_HEADER">
<column columnName="ORDER_NUMBER">00001</column>
<column columnName="Country">England</column>
<column columnName="City">London</column>
</row>
<row nodeName="ORDER_HEADER" tableName="ORDER_HEADER">
<column columnName="ORDER_NUMBER">00002</column>
<column columnName="Country">England</column>
<column columnName="City">Birmingham</column>
</row>
<row nodeName="ORDER_DETAIL" tableName="ORDER_DETAIL">
<column columnName="ORDER_NUMBER">00001</column>
<column columnName="Book">Gone with the wind</column>
<column columnName="Qty">2</column>
</row>
<row nodeName="ORDER_DETAIL" tableName="ORDER_DETAIL">
<column columnName="ORDER_NUMBER">00001</column>
<column columnName="Book">Pride and Prejudice</column>
<column columnName="Qty">3</column>
</row>
<row nodeName="ORDER_DETAIL" tableName="ORDER_DETAIL">
<column columnName="ORDER_NUMBER">00002</column>
<column columnName="Book">Jane Eyre</column>
<column columnName="Qty">1</column>
</row>
</output>
</Data>
我試圖創建以下的輸出:
<Transmission xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.w3.org/1999/xhtml">
<OrderNumber>00001</OrderNumber>
<Country>England</Country>
<City>London</CITY>
<Book>Gone with the wind</Book>
<QTY>2</QTY>
<Book>Pride and Prejudice</Book>
<QTY>3</QTY>
<OrderNumber>00002</OrderNumber>
<Country>England</Country>
<City>Birmingham</CITY>
<Book>Jane Eyre</Book>
<QTY>1</QTY>
</Transmission>
這裏是XSL我到目前爲止:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.w3.org/1999/xhtml">
<xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>
<xsl:template match="/Data/output[@outputType='CORRECTION']">
<Transmission>
<xsl:for-each select="row[@tableName='ORDER_HEADER']">
<OrderNumber>
<xsl:value-of select="column[@columnName='ORDER_NUMBER']" />
</OrderNumber>
<Country>
<xsl:value-of select="column[@columnName='Country']" />
</Country>
<City>
<xsl:value-of select="column[@columnName='City']" />
</City>
</xsl:for-each>
</Transmission>
</xsl:template>
</xsl:stylesheet>
我可以輸出來自每個訂單表頭的詳細信息,但無法看到如何選擇和分組正確的訂單詳細信息。任何幫助將非常感激。
感謝
完美!非常感謝您提供清晰簡潔的解決方案。這非常有幫助。 –