Xslt for-each and key match -


i have 2 xml data sources this:

<orders>  <order>   <ordernumber>123</ordernumber>   <subtotal>20</subtotal>   <total>23.5</total>  </order>   <order>   <ordernumber>234</ordernumber>   <subtotal>19</subtotal>   <total>26.5</total>  </order> </orders>  <orderitems>  <item>   <ordernumber>123</ordernumber>   <productname>test1</productname>   <sku>s9sdidk</sku>  <item>  <item>   <ordernumber>123</ordernumber>   <productname>test2</productname>   <sku>123232</sku>  <item>  <item>   <ordernumber>234</ordernumber>   <productname>test3</productname>   <sku>s9sd2d32k</sku>  <item>  <item>   <ordernumber>234</ordernumber>   <productname>test4</productname>   <sku>s9swe23</sku>  <item> </orderitems> 

and need use xslt group items order number , output this:

productname               sku test1                     s9sdidk test2                     123232 ---------------------------------    subtotal: 20    total: 23.5  productname               sku test3                     s9sd2d32k test4                     s9swe23 ---------------------------------    subtotal: 19    total: 26.5 

i need use html tags can't use for-each-group thing...please help! in advance.

this stylesheet:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform">     <xsl:output method="text"/>     <xsl:key name="kitembyordernumber" match="item" use="ordernumber"/>     <xsl:variable name="vsource2" select="document('source2.xml')"/>     <xsl:template match="text()"/>     <xsl:template match="order/ordernumber">         <xsl:variable name="vcurrent" select="."/>         <xsl:text>productname&#x9;&#x9;sku&#xa;</xsl:text>         <xsl:for-each select="$vsource2">             <xsl:apply-templates                      select="key('kitembyordernumber',$vcurrent)"/>         </xsl:for-each>         <xsl:value-of               select="concat('---------------------------------','&#xa;',                             '&#x9;subtotal: ',../subtotal,'&#xa;',                             '&#x9;total: ',../total,'&#xa;&#xa;')"/>     </xsl:template>     <xsl:template match="item">         <xsl:value-of select="concat(productname,'&#x9;&#x9;&#x9;',                                      sku,'&#xa;')"/>     </xsl:template> </xsl:stylesheet> 

with first document input , second document source2.xml external input, output:

productname     sku test1           s9sdidk test2           123232 ---------------------------------     subtotal: 20     total: 23.5  productname     sku test3           s9sd2d32k test4           s9swe23 ---------------------------------     subtotal: 19     total: 26.5 

Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -