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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Formatting my XML with an XSL sheet

Status
Not open for further replies.

timfoster

Programmer
Dec 19, 2002
110
GB
I have an xml document that I format into a table with an xsl sheet. This works OK, but I have a couple of bits that I can't seem to get.

1. I need to force <br> tags into the output. I have an address in a single cell and need each line of the address to be on different lines.
i.e.
Company Name
Address1
Address2
etc

2. I need to format the output differently from the data stored in XML. The original file has dates stored as dd mmm yyyy. I need the output to use this date and format it as ddmmyy.

3. I need my invoice lines to be alternately coloured.

Is any/all of this possible within my xsl sheet?
 
You should be able to put this into your XSL to get a break tag out.
Code:
<xsl:text>&lt;br&gt;</xsl:text>
Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Right folks,

I've worked out most of my problems with this. I have the invoice lines nicely coloured. I have the <br> tags nicely inserted. I'm still struggling a little with the format of the date (although I may true adding the date into teh XML in the format I need). The main problem I'm left with is subtotals!

I'm sure this is very simple indeed, but...

I have two nodes in my xml invoice. I have a series of parent nodes called INVOICE_LINE with a child of EXVAT and VAT. For each INVOICE_LINE I want to get a running total for EXVAT and VAT and then write these values out at the bottom, plus another element that adds these two together.

Surely this can't be that hard can it?
 
If the date is dd/mm/yyyy and you want dd/mm/yy, you could use string concatenation:

Code:
<xsl:value-of select="concat(substring(string(theNode),1,6),substring(string(theNode),9,2))" />

For the subtotals, you could use recursion with templates or use variables. Recursion would be nicer I think. If you post the XML and a better explanation of exactly what you want I could post an example, I'm bored at work.

Jon
 
Thanks Jon, lol. I think I've sussed it out now. I've added some java to the template that adds the values of ExVat and Vat to a running variable throughout the document. Once it has processed all the lines, I use a document.write() to put the value onto the page. It works a treat!!!!!

But...

If you're still bored...

Can I format a date from 2 Dec 2004 to 021204 using the xml template?
 
Code:
<xsl:template match="/">
	<xsl:call-template name="formatDate">
			<xsl:with-param name="date" select="theDateNode" />
	</xsl:call-template>
</xsl:template>

<xsl:template name="formatDate">
	<xsl:param name="date" />
	<xsl:variable name="day">
		<xsl:choose>
			<xsl:when test="string-length(substring-before($date, ' '))=1">
				<xsl:value-of select="concat('0', substring-before($date, ' '))" />
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="substring-before($date, ' ')" />
			</xsl:otherwise>
		</xsl:choose>
	</xsl:variable>
	<xsl:variable name="month" select="substring(substring-after('jan01feb02mar03apr04may05jun06jul07aug08sep09oct10nov11dec12', substring(substring-after($date, ' '), 1, 3)), 1, 2)" />
	<xsl:variable name="year" select="substring(substring-after($date, ' '), 7, 2)" />
	<xsl:value-of select="concat($day, $month, $year)" />
</xsl:template>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top