Click here to Skip to main content
15,900,511 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
How can i write multiple values in the same line and value should be write between specific position.

XML File:
<?xml version="1.0" encoding="us-ascii" standalone="yes"?>
	<InvoiceHeader CustomerName="Pankaj" Address="Address1" City="SURAT" BillNo= "123" Date="02/08/2018"></InvoiceHeader >
	<Product ID="1" Name="KeyBoard" Qty="25" Price="250.00"></Product>
	<Product ID="2" Name="Monitor" Qty="15" Price="6700.00"></Product>
	<Product ID="3" Name="CPU" Qty="5" Price="11000.00"></Product>

Output Text File:

Customer: PANKAJ		           Date: 02/08/2018
Address: ADDRESS1				   BillNo: 123

SrNo	Item				QTY	  Price	           Amount
1	keyboard           0025	000250.00          00006250.00
2	Monitor		       0015	006700.00          00100500.00
3	CPU	               0005	011000.00          00055000.00
	Total			   0045	     	           00461750.00

What I have tried:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="">
<xsl:output method="text"/>
<xsl:template match="/">
Customer: </xsl:text><xsl:value-of select="Invoice/InvoiceHeader/@CustomerName" /><xsl:text>	</xsl:text><xsl:text>	</xsl:text>
<xsl:text> Date: </xsl:text><xsl:value-of select="Invoice/InvoiceHeader/@Date" /><xsl:text></xsl:text><xsl:text></xsl:text>
Address: </xsl:text><xsl:value-of select="Invoice/InvoiceHeader/@Address" /><xsl:text></xsl:text>
City: </xsl:text><xsl:value-of select="Invoice/InvoiceHeader/@City" /><xsl:text>	</xsl:text><xsl:text>	</xsl:text>

<xsl:text>BillNo: </xsl:text><xsl:value-of select="Invoice/InvoiceHeader/@BillNo" />
City: </xsl:text><xsl:value-of select="Invoice/InvoiceHeader/@City" /><xsl:text></xsl:text>
<xsl:text>SrNo</xsl:text><xsl:text>	</xsl:text>	
<xsl:text>Item</xsl:text><xsl:text>	</xsl:text>
<xsl:text>Qty</xsl:text><xsl:text>	</xsl:text>
<xsl:text>Price</xsl:text><xsl:text>	</xsl:text>
<xsl:for-each select="Invoice/Product">
<xsl:value-of select="./@ID" /><xsl:text>	</xsl:text>
<xsl:value-of select="./@Name" /><xsl:text>	</xsl:text>
<xsl:value-of select="./@Qty" /><xsl:text>	</xsl:text>
<xsl:value-of select="./@Price" /><xsl:text>	</xsl:text>
<xsl:value-of select="./@Qty * ./@Price" /><xsl:text></xsl:text>


Updated 17-Apr-21 1:44am
Patrice T 20-Aug-18 4:14am    
You forgot to list your xslt file.
Eric Lynch 20-Aug-18 8:00am    
I agree with ppolymorphe, you need to add your XSLT file to the question. Because its missing, I'm guessing (maybe) you didn't try anything yet. Give it a try!

Update your original question to add the XSLT and ask for more specific help. Then, I think you'd find a lot more people willing to help you. Few people, myself included, are likely to write the entire thing for you. We usually get paid for that sort of "help" :)

Here are a couple of links to get you started. Good luck.

Also, you might want to mention how you plan to execute the XSLT transform. For example, are you planning to use a command line tool? If so, which one? Or, are you planning to invoke it from some programming language? If so, which one?
OriginalGriff 20-Aug-18 4:15am    
What help do you want from us?
Where are you stuck?
What have you tried?
We have no idea what code you are using, not even the language!

This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with.
Use the "Improve question" widget to edit your question and provide better information.
Nelek 23-Aug-18 7:02am    
he updated, I still don't understand well what he wants, but you might want to have a try :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900