Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Identitity Template Problem - Best Practices - What order to make changes

From: johkar <nosendjunk@---.--->
To: NULL
Date: 10/18/2009 4:18:00 PM
I have source XML that is 5-10 MB in size.  I am transforming it from
XML to XML. I am having some issues with overwriting changes that I
have already made.  I have come to the realization when using template
match you need to do things in a certain order so as to not overwrite
changes already made.  For example if you first remove all currency
formatting on the entire document and then copy nodes containing
formatted currency to a new level...the currency formatting is back.

There are five things I need to do with the XML...at various levels
and in more than one place...nothing too complicated:

1) Replace element names
2) Make elements child elements by adding a brand new parent node.
3) Remove elements entirely
4) Add new elements/values
5) Remove all currency formatting

My questions are:
1) Do I work from the root element and go deeper so that I don't
overwrite...in general what is the best strategy?
2) Do I have one identity template and one primary template match that
I put all my apply-templates within so that nothing is copied to the
output until all changes are made?
3) How can I use a common template to strip currency formatting for
any section of the XML that I might also be doing other changes too?
There is probably an easier template remove formatting than the one I
am using below.

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
	<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/
>

	<!-- COPY EVERYTHING -->
	<xsl:template match="node() | @*">
		<xsl:copy>
			<xsl:apply-templates select="@* | node()"/>
		</xsl:copy>
	</xsl:template>

                <!-- REMOVE CURRENCY FORMATTING -->
	<xsl:template match="text()[starts-with(.,'$') or starts-with(.,'($')
or starts-with(.,'-$') or contains(.,',')]">

		<!-- REPLACE LEADING PARENTHESIS WITH MINUS SIGN AND REMOVE COMMAS --
>

		<xsl:variable name="txt" select="translate(translate
(.,',',''),'(','-')"/>

		<xsl:choose>
			<!--REMOVE ALL CHARACTERS EXCEPT NUMBERS, DECIMALS AND MINUS SIGNS--
>
			<xsl:when test="starts-with($txt,'$') or starts-with($txt,'-$')">
				<xsl:value-of select="translate($txt,translate
($txt,'0123456789.-',''),'')"/>
			</xsl:when>
			<!--FOR FIELDS WITHOUT DOLLAR SIGNS, TEST TO SEE IF NUMBER-->
			<xsl:when test="number($txt) = number($txt)">
				<xsl:value-of select="$txt"/>
			</xsl:when>
			<!--PASS THROUGH TEXT BECAUSE IT IS NOT A NUMBER-->
			<xsl:otherwise>
				<xsl:value-of select="."/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
</xsl:stylesheet>


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