Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

xml to xml using xslt - only first record showing duplicate times 2

Status
Not open for further replies.

angbain

Programmer
Apr 29, 2006
5
GB
Hi..i've been tearing my hair out all week trying different methods to transform my xml file to another xml file with a different format...i'm a bit of a newbie to xslt. Anyway i've managed to get the format the way i want it but i'm only getting the first record of the origional xml file duplicated in the output xml file..please see below for example xml data and stylesheet..any help/idea's would much appreciated..


<b>sample origional xml</b>

- <ABWTransaction Version="5.4" xmlns:sql="urn:schemas-microsoft-com:xml-sql">
<Interface>Bl</Interface>
<BatchId>YPO</BatchId>
- <Voucher>
<VoucherType>94</VoucherType>
<CompanyCode>W5</CompanyCode>
<VoucherDate />
- <Transaction>
<TransType>GL</TransType>
<Transdate>2006-04-27T16:54:31.347</Transdate>
<TaxCode>P2</TaxCode>
<Number1>000100</Number1>
<InvoiceNo>714208</InvoiceNo>
<Dim7 />
<Dim1 />
<Description>SINGLE HOLE MINI PUNCH</Description>
<Currency>GBP</Currency>
<CurrAmount>00000050</CurrAmount>
<Amount>00000050</Amount>
<Account>0000</Account>
<RecordID>1</RecordID>
</Transaction>
- <Transaction>
<TransType>GL</TransType>
<Transdate>2006-04-27T16:54:31.347</Transdate>
<TaxCode>P2</TaxCode>
<Number1>000100</Number1>
<InvoiceNo>722715</InvoiceNo>
<Dim7 />
<Dim1 />
<Description>EXECUTIVE FOLDOVER CLIP BOARD</Description>
<Currency>GBP</Currency>
<CurrAmount>00000098</CurrAmount>
<Amount>00000098</Amount>
<Account>0000</Account>
<RecordID>2</RecordID>
</Transaction>
- <Transaction>
<TransType>GL</TransType>
<Transdate>2006-04-27T16:54:31.347</Transdate>
<TaxCode>P2</TaxCode>
<Number1>000100</Number1>
<InvoiceNo>763217</InvoiceNo>
<Dim7 />
<Dim1 />
<Description>A4 CUT FLUSH FOLDERS ASST COL PK 25</Description>
<Currency>GBP</Currency>
<CurrAmount>00000095</CurrAmount>
<Amount>00000095</Amount>
<Account>0000</Account>
<RecordID>3</RecordID>
</Transaction>
- <Transaction>
<TransType>GL</TransType>
<Transdate>2006-04-27T16:54:31.347</Transdate>
<TaxCode>P2</TaxCode>
<Number1>000100</Number1>
<InvoiceNo>313173</InvoiceNo>
<Dim7 />
<Dim1 />
<Description>SCISSOR 15CM STAINLESS STEEL</Description>
<Currency>GBP</Currency>
<CurrAmount>00000140</CurrAmount>
<Amount>00000140</Amount>
<Account>0000</Account>
<RecordID>4</RecordID>
</Transaction>
- <Transaction>
<TransType>GL</TransType>
<Transdate>2006-04-27T16:54:31.347</Transdate>
<TaxCode>P2</TaxCode>
<Number1>000100</Number1>
<InvoiceNo>761702</InvoiceNo>
<Dim7 />
<Dim1 />
<Description>A4 OVERSIZED PUNCHED POCKETS PK 100</Description>
<Currency>GBP</Currency>
<CurrAmount>00000470</CurrAmount>
<Amount>00000470</Amount>
<Account>0000</Account>
<RecordID>5</RecordID>
</Transaction>
</Voucher>
</ABWTransaction>

<b>sample style sheet</b>

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet xmlns:xsl=" version="1.0">
<xsl:eek:utput method="xml" indent="yes" encoding="uft-8" omit-xml-declaration="no" />

<xsl:template match="/">
<ABWTransaction Version="5.4" xmlns:sql="urn:schemas-microsoft-com:xml-sql">
<Interface>Bl</Interface>
<BatchId>YPO</BatchId>
<Voucher>
<VoucherType>94</VoucherType>
<CompanyCode>W5</CompanyCode>
<VoucherDate><xsl:value-of select="/ABWTransaction/Voucher/Transaction/Transdate" /> </VoucherDate>

<xsl:apply-templates select="/ABWTransaction/Voucher/Transaction" />

</Voucher>
</ABWTransaction>

</xsl:template>

<xsl:template match= "Transaction">
<!--<xsl:for-each select="/ABWTransaction/Voucher/Transaction">-->
<xsl:element name="Transaction">
<xsl:element name="Transtype">
<xsl:value-of select="/ABWTransaction/Voucher/Transaction/TransType" />
</xsl:element>
<xsl:element name="Description">
<xsl:value-of select="/ABWTransaction/Voucher/Transaction/Description" />
</xsl:element>
<!--<xsl:copy-of select="/ABWTransaction/Voucher/Transaction/Description" />-->
<xsl:element name="TransDate">
<xsl:value-of select="/ABWTransaction/Voucher/Transaction/Transdate" />
</xsl:element>

<xsl:element name="Amounts">
<xsl:element name="CurrAmount">
<xsl:value-of select="/ABWTransaction/Voucher/Transaction/CurrAmount"/>
</xsl:element>
<xsl:element name="Amount">
<xsl:value-of select="/ABWTransaction/Voucher/Transaction/Amount"/>
</xsl:element>
</xsl:element>


<xsl:element name="GLAnalysis">

<xsl:element name="TaxCode">
<xsl:value-of select="/ABWTransaction/Voucher/Transaction/TaxCode" />
</xsl:element>
<xsl:element name="Number1">
<xsl:value-of select="/ABWTransaction/Voucher/Transaction/Number1" />
</xsl:element>
<xsl:element name="InvoiceNo">
<xsl:value-of select="/ABWTransaction/Voucher/Transaction/InvoiceNo" />
</xsl:element>

<xsl:element name="Dim7">
<xsl:value-of select="/ABWTransaction/Voucher/Transaction/Dim7"/>
</xsl:element>
<xsl:element name="Dim6">
<xsl:value-of select="/ABWTransaction/Voucher/Transaction/Dim6"/>
</xsl:element>

<xsl:element name="Dim1">
<xsl:value-of select="/ABWTransaction/Voucher/Transaction/Dim1" />
</xsl:element>

<xsl:element name="Currency">
<xsl:value-of select="/ABWTransaction/Voucher/Transaction/Currency"/>
</xsl:element>
<xsl:element name="Account">
<xsl:value-of select="/ABWTransaction/Voucher/Transaction/Account"/>
</xsl:element>
</xsl:element>
</xsl:element>


<!--</xsl:for-each>-->

</xsl:template>


</xsl:stylesheet>

<b>example output xml</b>

<?xml version="1.0" encoding="utf-8" ?>
- <ABWTransaction Version="5.4" xmlns:sql="urn:schemas-microsoft-com:xml-sql">
<Interface>Bl</Interface>
<BatchId>YPO</BatchId>
- <Voucher>
<VoucherType>94</VoucherType>
<CompanyCode>W5</CompanyCode>
<VoucherDate>2006-04-27T16:54:31.347</VoucherDate>
- <Transaction>
<Transtype>GL</Transtype>
<Description>SINGLE HOLE MINI PUNCH</Description>
<TransDate>2006-04-27T16:54:31.347</TransDate>
- <Amounts>
<CurrAmount>00000050</CurrAmount>
<Amount>00000050</Amount>
</Amounts>
- <GLAnalysis>
<TaxCode>P2</TaxCode>
<Number1>000100</Number1>
<InvoiceNo>714208</InvoiceNo>
<Dim7 />
<Dim6 />
<Dim1 />
<Currency>GBP</Currency>
<Account>0000</Account>
</GLAnalysis>
</Transaction>
- <Transaction>
<Transtype>GL</Transtype>
<Description>SINGLE HOLE MINI PUNCH</Description>
<TransDate>2006-04-27T16:54:31.347</TransDate>
- <Amounts>
<CurrAmount>00000050</CurrAmount>
<Amount>00000050</Amount>
</Amounts>
- <GLAnalysis>
<TaxCode>P2</TaxCode>
<Number1>000100</Number1>
<InvoiceNo>714208</InvoiceNo>
<Dim7 />
<Dim6 />
<Dim1 />
<Currency>GBP</Currency>
<Account>0000</Account>
</GLAnalysis>
</Transaction>
- <Transaction>
<Transtype>GL</Transtype>
<Description>SINGLE HOLE MINI PUNCH</Description>
<TransDate>2006-04-27T16:54:31.347</TransDate>
- <Amounts>
<CurrAmount>00000050</CurrAmount>
<Amount>00000050</Amount>
</Amounts>
- <GLAnalysis>
<TaxCode>P2</TaxCode>
<Number1>000100</Number1>
<InvoiceNo>714208</InvoiceNo>
<Dim7 />
<Dim6 />
<Dim1 />
<Currency>GBP</Currency>
<Account>0000</Account>
</GLAnalysis>
</Transaction>
- <Transaction>
<Transtype>GL</Transtype>
<Description>SINGLE HOLE MINI PUNCH</Description>
<TransDate>2006-04-27T16:54:31.347</TransDate>
- <Amounts>
<CurrAmount>00000050</CurrAmount>
<Amount>00000050</Amount>
</Amounts>
- <GLAnalysis>
<TaxCode>P2</TaxCode>
<Number1>000100</Number1>
<InvoiceNo>714208</InvoiceNo>
<Dim7 />
<Dim6 />
<Dim1 />
<Currency>GBP</Currency>
<Account>0000</Account>
</GLAnalysis>
</Transaction>
- <Transaction>
<Transtype>GL</Transtype>
<Description>SINGLE HOLE MINI PUNCH</Description>
<TransDate>2006-04-27T16:54:31.347</TransDate>
- <Amounts>
<CurrAmount>00000050</CurrAmount>
<Amount>00000050</Amount>
</Amounts>
- <GLAnalysis>
<TaxCode>P2</TaxCode>
<Number1>000100</Number1>
<InvoiceNo>714208</InvoiceNo>
<Dim7 />
<Dim6 />
<Dim1 />
<Currency>GBP</Currency>
<Account>0000</Account>
</GLAnalysis>
</Transaction>
</Voucher>
</ABWTransaction>


thanks
Ang [ponder]
 
You need to understand the context within the template. Your xsl:value-of instructions, within the Transaction template, are using XPath expressions that ignore the context, thereby getting the first value each time through. Try using this style to take advantage of the correct context:
Code:
<xsl:template match= "Transaction">
        <!--<xsl:for-each select="/ABWTransaction/Voucher/Transaction">-->    
            <Transaction>
                <xTranstype>
                    <xsl:value-of select="TransType" />
                </xTranstype>
[i]etc.[/i]

Tom Morrison
 
thankx i'll give this a go and let u know what happens...cheers angxx
 
i can't get on to my server at the moment can u tell me what difference <xTranstype> to <Transtype> is please..

cheers
Ang
 
Hi tried the above but get same result...thanks ang
 
This is what k5tm meant using the context for that particular template. I think what said is correct and should do.
[tt]
<xsl:template match= "Transaction">
<!--<xsl:for-each select="/ABWTransaction/Voucher/Transaction">-->
<xsl:element name="Transaction">
<xsl:element name="Transtype">
<xsl:value-of select="TransType" />
</xsl:element>
<xsl:element name="Description">
<xsl:value-of select="Description" />
</xsl:element>
<!--<xsl:copy-of select="/ABWTransaction/Voucher/Transaction/Description" />-->
<xsl:element name="TransDate">
<xsl:value-of select="Transdate" />
</xsl:element>

<xsl:element name="Amounts">
<xsl:element name="CurrAmount">
<xsl:value-of select="CurrAmount"/>
</xsl:element>
<xsl:element name="Amount">
<xsl:value-of select="Amount"/>
</xsl:element>
</xsl:element>

<xsl:element name="GLAnalysis">
<xsl:element name="TaxCode">
<xsl:value-of select="TaxCode" />
</xsl:element>
<xsl:element name="Number1">
<xsl:value-of select="Number1" />
</xsl:element>
<xsl:element name="InvoiceNo">
<xsl:value-of select="InvoiceNo" />
</xsl:element>
<xsl:element name="Dim7">
<xsl:value-of select="Dim7"/>
</xsl:element>
<xsl:element name="Dim6">
<xsl:value-of select="Dim6"/>
</xsl:element>
<xsl:element name="Dim1">
<xsl:value-of select="Dim1" />
</xsl:element>
<xsl:element name="Currency">
<xsl:value-of select="Currency"/>
</xsl:element>
<xsl:element name="Account">
<xsl:value-of select="Account"/>
</xsl:element>
</xsl:element>
</xsl:element>

<!--</xsl:for-each>-->

</xsl:template>
[/tt]
 
Thanks guys...its working now i hadn't taken the path out of the value-of select before...[bigsmile]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top