xsl-list
[Top] [All Lists]

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

2009-05-28 04:48:04
hi,Michael Kay,  oh yes, I think you are right. This file is used in
Microsoft's workflow product. But your knowledge on file format is
amazing! :) My task is to standardize the elements' and attributes'
name in thousands of these files. But Xml manipulation API cann't
change these names. I search the solution in web and people say it can
be done with XSLT. So I want to try. Actually the job is a little
complicated than this. But I think from this point I can find the way
myself. I just want to learn new things. If I cann't tackle it with
XSLT, I can still using regular expression to do the work. Thank you
very much!

2009/5/28 Michael Kay <mike(_at_)saxonica(_dot_)com>:

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="http://www.w3.org/TR/WD-xsl";>
      <xsl:template match=" / ">
              <HTML>
                      <BodY bgColor="#c0c0c0" Class="screen"
FNSType="SINGLEPAGESCREEN"
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
stylesheet:

<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

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

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

</xsl:stylesheet>

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

lower-case(X)

by

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

Regards,

Michael Kay
http://www.saxonica.com/
http://twitter.com/michaelhkay


--~------------------------------------------------------------------
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>
--~--



--~------------------------------------------------------------------
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>
--~--