This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: lowercasing all attributes...
- From: Steve Ball <Steve dot Ball at zveno dot com>
- To: xsl-list at lists dot mulberrytech dot com
- Date: Tue, 29 Jan 2002 12:13:55 +1100
- Subject: Re: [xsl] lowercasing all attributes...
- Organization: Zveno Pty Ltd
- References: <008401c1a786$bc8f9ff0$0a00a8c0@earth>
- Reply-to: xsl-list at lists dot mulberrytech dot com
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@zveno.com +---------------------------+---------------------
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