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

Re: lowercasing all attributes...

Subject: Re: lowercasing all attributes...
From: Steve Ball <Steve.Ball@xxxxxxxxx>
Date: Tue, 29 Jan 2002 12:13:55 +1100
select nodes case insensitive
Martijn wrote:

I'd like to lowercase a document's attributes through <xsl:apply-templates
select="???">


Do you mean that you'd like to select nodes based on their
attribute names or values, but in a case-insensitive manner?

See below.


I know it's translate(., 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
'abcdefghijklmnopqrstuvwxyz') but how 'bout the template match pattern and
the select for apply-templates ??


That's basically correct, for English. You may wish to

use the XSLT Standard Library's to-lower template in order

to handle non-English case folding.


Unfortunately, XSLT v1.0 doesn't provide a way of defining a function in the stylesheet so we have to do things the hard way. If I'm looking for the attribute named 'foo', but in any permutation of case ('Foo', 'FOO', etc), try this(*):

<xsl:template match='*'>
  <xsl:for-each select='@*'>
    <xsl:variable name='lower'>
      <xsl:call-template name='str:to-lower'>
        <xsl:with-param name='text' select='.'/>
      </xsl:call-template>
    </xsl:variable>

    <xsl:if test='$lower = "foo"'>
      <!-- This is the one I want -->
    </xsl:if>
  </xsl:for-each>
</xsl:template>

Of course, using translate() is much more succinct:

<xsl:template match='*/@*[translate(., "ABC...", "abc...") = "foo"]'>
  <!-- This is the one I want -->
</xsl:template>

but as I mentioned above doesn't handle case-folding in general.

* You must setup XSLTSL to work in your stylesheet.
  See http://xsltsl.sf.net/ for instructions on how to do that.

HTHs,
Steve Ball

--
Steve Ball            |   XSLT Standard Library   | Training & Seminars
Zveno Pty Ltd         |     Web Tcl Complete      |   XML XSL Schemas
http://www.zveno.com/ |      TclXML TclDOM        | Tcl, Web Development
Steve.Ball@xxxxxxxxx  +---------------------------+---------------------
Ph. +61 2 6242 4099   |   Mobile (0413) 594 462   | Fax +61 2 6242 4099


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



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.