xsl-list
[Top] [All Lists]

RE: How to change element nodes cases?

2003-03-31 10:28:55
Hi.

-----Mensagem original-----
De: owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com 
[mailto:owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com] Em nome de 
Michael Liwanag
Enviada: segunda-feira, 31 de Marco de 2003 2:42
Para: XSL-List(_at_)lists(_dot_)mulberrytech(_dot_)com
Assunto: [xsl] How to change element nodes cases?


How can I change this form:
<customer> Michael </customer>
to 
<Customer> Michael </Customer>


This template will change the case of all your elements:
 <xsl:variable name="upper" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>
 <xsl:variable name="lower" select="'abcdefghijklmnopqrstuvwxyz'"/>
 
 <xsl:template match="*">
  <xsl:variable name="pref"
select="substring-before(name(),local-name())"/>
  <xsl:element
name="{concat($pref,translate(substring(local-name(),1,1),$lower,$upper)
,translate(substring(local-name(),2),$upper,$lower))}"
namespace="{namespace-uri()}">
   <xsl:apply-templates select="node()|@*"/>
  </xsl:element>
 </xsl:template>

Applyied to this source:
<doc xmlns:y="test2">
 <costumer>
  <prep/>
 </costumer>
 <test/>
 <x:test xmlns:x="test1"/>
 <x:opps xmlns:x="test1">
  <y:test/>
 </x:opps>
</doc>

Result in this:
<Doc>
 <Costumer>
  <Prep/>
 </Costumer>
 <Test/>
 <x:Test xmlns:x="test1"/>
 <x:Opps xmlns:x="test1">
  <y:Test xmlns:y="test2"/>
 </x:Opps>
</Doc>


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



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