[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Attribute and Element Formatting Issues

Subject: Re: Attribute and Element Formatting Issues
From: "Joris Gillis" <roac@xxxxxxxxxx>
Date: Tue, 13 Sep 2005 16:56:48 +0200
xslt capitalize
Hi,

Tempore 16:08:57, die 09/13/2005 AD, hinc in xsl-list@xxxxxxxxxxxxxxxxxxxxxx scripsit Mehta, Chirag <chirag.mehta@xxxxxxxxxxxxxxxxx>:

<?xml version="1.0" encoding="utf-8"?>
<portfolio name="CBOT" version="1">
   <trade name="Future" quantity="1">
      <instrument instType="Bond">
         <dictionary>
            <dict name="expiry date" type="t">
            </dict>

<dict name="strike" type="d">0.95</dict>

            <dict name="option type" type="s">EuropeanCall</dict>
         </dictionary>
      </instrument>
   </trade>
</portfolio>


TO:


<?xml version="1.0" encoding="utf-8"?>
<portfolio name="CBOT" version="1">
   <trade name="Future" quantity="1">
      <instrument instType="Bond">
         <expiryDate>
         </expiryDate>

<strike>0.95</strike>

         <optionType>EurpoeanCall</optionType>
      </instrument>
   </trade>
</portfolio>

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

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

<xsl:template match="dictionary"><xsl:apply-templates/></xsl:template>

<xsl:template match="dict">
	<xsl:variable name="new_name">
		<xsl:call-template name="capitalize">
			<xsl:with-param name="string" select="@name"/>
		</xsl:call-template>
	</xsl:variable>
	<xsl:element name="{$new_name}"><xsl:apply-templates/></xsl:element>
</xsl:template>

<xsl:template name="capitalize">
<xsl:param name="string"/>
<xsl:param name="caps" select="false()"/>
<xsl:if test="contains($string,' ')">
	<xsl:if test="$caps">
		<xsl:value-of select="translate(substring(substring-before($string,' '),1,1),'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ')"/>
		<xsl:value-of select="substring(substring-before($string,' '),2)"/>
	</xsl:if>
	<xsl:if test="not($caps)">
		<xsl:value-of select="substring-before($string,' ')"/>
	</xsl:if>
	<xsl:call-template name="capitalize">
		<xsl:with-param name="string" select="substring-after($string,' ')"/>
		<xsl:with-param name="caps" select="true()"/>
	</xsl:call-template>
</xsl:if>
<xsl:if test="not(contains($string,' '))">
	<xsl:if test="$caps">
		<xsl:value-of select="translate(substring($string,1,1),'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ')"/>
		<xsl:value-of select="substring($string,2)"/>
	</xsl:if>
	<xsl:if test="not($caps)">
		<xsl:value-of select="$string"/>
	</xsl:if>
</xsl:if>
</xsl:template>

</xsl:stylesheet>


regards, -- Joris Gillis (http://users.telenet.be/root-jg/me.html) B+Et ipsa scientia potestas estB; - Francis Bacon , Meditationes sacrae

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.