RE: [xsl] template to convert all attributes' name to lowercase

Subject: RE: [xsl] template to convert all attributes' name to lowercase
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Thu, 28 May 2009 09:04:05 +0100
> I hava a task to convert all attributes' name in a xslt file 
> to lowercase. Actually I don't know whether it's a xslt file. 

It's not an XSLT file, it's a stylesheet written in an obsolete Microsoft
language (often called WD-xsl) that was based on an early draft of XSLT,
with Microsoft additions and deletions.

> It looks strange, like this:
> <?xml version="1.0"?>
> <xsl:stylesheet xmlns:xsl="";>
> 	<xsl:template match=" / ">
> 		<HTML>
> 			<BodY bgColor="#c0c0c0" Class="screen" 
> id="FNSScreen">
> 			//many html things go here.
> 			</BodY>
> 		</HTML>
> 	</xsl:template>
> </xsl:stylesheet>

> I'm a novice of  xslt and have only two days to finish this task.

Usually if a task is urgent and the user is a novice I reckon the best
advice I can give is "don't even attempt it, you will only make a mess of
it". However this one is fairly easy. I suspect you want to change the
element names to lower-case too? That's essentially a modified identity

<xsl:stylesheet version="2.0"
  <xsl:template match="*">
    <xsl:element name="lower-case(name())" namespace="{namespace-uri()}">
      <xsl:apply-templates select="@* | node()"/>

  <xsl:template match="@*">
    <xsl:attribute name="lower-case(name())" namespace="{namespace-uri()}">
      <xsl:value-of select="."/>


That solution uses XSLT 2.0. If for some reason you have to use XSLT 1.0,
you can replace



translate(X, 'ABCDE....Z', 'abcde....z')


Michael Kay 

Current Thread