Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Help with XSLT - how to flatten ?

From: "Rob C" <rwc1960@---------.--->
To: NULL
Date: 10/1/2004 8:03:00 AM
Is there a way to reference "children" in the line below  marked by the word 
CHANGE ?

>> <xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>> version="1.0">
>> <xsl:output method ="xml" encoding ="UTF-8"/>
>>
>> <xsl:template match="Invoice">
>> <xsl:variable name="a" select="@id"/>
>> <xsl:variable name="b" select="Supplier"/>
>> <xsl:for-each select="InvoiceItems/InvoiceItem">
>> <xsl:call-template name="InvoiceItem">
>>   <xsl:with-param name="id" select="$a"/>
>>   <xsl:with-param name="supplier" select="$b"/>
>> </xsl:call-template>
>> </xsl:for-each>
>> </xsl:template>
>>
>> <xsl:template name="InvoiceItem">
>> <xsl:param name="id"/>
>> <xsl:param name="supplier"/>
CHANGE ?>> <InvoiceItem id ="{$id}" Supplier="{$supplier}" line ="{@line}"
>> NetAmount="{NetAmount}"   (can you reference children here - sample below 
>> ?) />
>> </xsl:template>
>>
>> <xsl:template match="Invoices">
>> <InvoiceItems>
>> <xsl:apply-templates/>
>> </InvoiceItems>
>> </xsl:template>
>> </xsl:transform>
>>
>>


"Rob C" <rwc1960@b...> wrote in message 
news:DrL6d.2589$yp.2157@b......
> Thank you Chris... suppose I added another layer within the InvoiceItem. 
> How would I bring that into the flat structure as well ?
> - Rob
>
> <Invoices>
> <Invoice id="ABC">
> <Supplier>123</Supplier>
> <InvoiceItems>
> <InvoiceItem 
> line="1"><NetAmount>2.88</NetAmount><Codes><Code1>ABC</Code1><Code2>DEF</Code2></Codes>
> </InvoiceItem>
> <InvoiceItem 
> line="2"><NetAmount>1.88</NetAmount><Codes><Code1>VBH</Code1><Code2>LKJ</Code2></Codes>
> </InvoiceItem>
> </InvoiceItems>
> </Invoice>
> <Invoice id="DEF">
> <Supplier>568</Supplier>
> <InvoiceItems>
> <InvoiceItem 
> line="1"><NetAmount>7.00</NetAmount><Codes><Code1>VPP</Code1><Code2>LRE</Code2></Codes>
> </InvoiceItem>
> <InvoiceItem 
> line="2"><NetAmount>9.00</NetAmount><Codes><Code1>ZAQ</Code1><Code2>WIJ</Code2></Codes>
> </InvoiceItem>
> </InvoiceItems>
> </Invoice>
> </Invoices>
>
>
>
>
>
> "Chris Lovett" <clovett-at-microsoft-dot-com> wrote in message 
> news:10li5hapq1huk33@c......
>> You could turn the inner template into a named template with parameters 
>> then use call-template as follows:
>>
>> <xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>> version="1.0">
>> <xsl:output method ="xml" encoding ="UTF-8"/>
>>
>> <xsl:template match="Invoice">
>> <xsl:variable name="a" select="@id"/>
>> <xsl:variable name="b" select="Supplier"/>
>> <xsl:for-each select="InvoiceItems/InvoiceItem">
>> <xsl:call-template name="InvoiceItem">
>>   <xsl:with-param name="id" select="$a"/>
>>   <xsl:with-param name="supplier" select="$b"/>
>> </xsl:call-template>
>> </xsl:for-each>
>> </xsl:template>
>>
>> <xsl:template name="InvoiceItem">
>> <xsl:param name="id"/>
>> <xsl:param name="supplier"/>
>> <InvoiceItem id ="{$id}" Supplier="{$supplier}" line ="{@line}" 
>> NetAmount="{NetAmount}"/>
>> </xsl:template>
>>
>> <xsl:template match="Invoices">
>> <InvoiceItems>
>> <xsl:apply-templates/>
>> </InvoiceItems>
>> </xsl:template>
>> </xsl:transform>
>>
>>
>>
>> "Rob C" <rwc1960@b...> wrote in message 
>> news:4i06d.2888$bq6.1790@b......
>>>
>>> I am trying to "flatten" the following xml... so that it essentially 
>>> repeats the Invoice and Supplier on each invoice line.
>>>
>>> I started an xslt file below which puts them on separate rows, but how 
>>> can I combine them into one row ?
>>>
>>>
>>> <Invoices>
>>> <Invoice id="ABC">
>>> <Supplier>123</Supplier>
>>> <InvoiceItems>
>>> <InvoiceItem line="1"><NetAmount>2.88</NetAmount>
>>> </InvoiceItem>
>>> <InvoiceItem line="2"><NetAmount>1.88</NetAmount>
>>> </InvoiceItem>
>>> </InvoiceItems>
>>> </Invoice>
>>> <Invoice id="DEF">
>>> <Supplier>568</Supplier>
>>> <InvoiceItems>
>>> <InvoiceItem line="1"><NetAmount>7.00</NetAmount>
>>> </InvoiceItem>
>>> <InvoiceItem line="2"><NetAmount>9.00</NetAmount>
>>> </InvoiceItem>
>>> </InvoiceItems>
>>> </Invoice>
>>> </Invoices>
>>>
>>>
>>> <xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
>>> version="1.0">
>>> <xsl:output method ="xml" encoding ="UTF-8"/>
>>>
>>> <xsl:template match="Invoice">
>>> <Invoice id ="{@id}" Supplier="{Supplier}"/>
>>> <xsl:apply-templates/>
>>> </xsl:template>
>>>
>>> <xsl:template match="InvoiceItem">
>>> <InvoiceItem line ="{@line}" NetAmount="{NetAmount}"/>
>>> <xsl:apply-templates/>
>>> </xsl:template>
>>>
>>>
>>> <xsl:template match="Invoices">
>>> <Invoices>
>>> <xsl:apply-templates/>
>>> </Invoices>
>>> </xsl:template>
>>> </xsl:transform>
>>>
>>>
>>
>>
>
> 




transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent