xsl-list
[Top] [All Lists]

Re: Attribute and Element Formatting Issues

2005-09-13 07:56:48
Hi,

Tempore 16:08:57, die 09/13/2005 AD, hinc in 
xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com scripsit Mehta, Chirag 
<chirag(_dot_)mehta(_at_)bankofamerica(_dot_)com>:

<?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)
«Et ipsa scientia potestas est»  - Francis Bacon , Meditationes sacrae

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>