Altova Mailing List Archives>Archive Index >microsoft.public.xml Archive Home >Recent entries >Thread Prev - Re: Help with XSLT - how to flatten ? [Thread Next] Re: Help with XSLT - how to flatten ?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>
>>>
>>>
>>
>>
>
>
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
