Discussion:
IGNORE CASE IN XSLT match
Senthilukvelaan
2008-10-01 05:12:50 UTC
Permalink
Hi All,
I would like to find out ,is there any way to ignore case while match
template in XSLT.




Thanks,
Sen

--~------------------------------------------------------------------
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-***@lists.mulberrytech.com>
--~--
Scott Trenda
2008-10-01 05:16:11 UTC
Permalink
<xsl:template match="*[translate(local-name(),
'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') = 'name']">
...
</xsl:template>


-----Original Message-----
From: Senthilukvelaan [mailto:***@googlemail.com]
Sent: Wednesday, October 01, 2008 12:13 AM
To: xsl-***@lists.mulberrytech.com
Subject: [xsl] IGNORE CASE IN XSLT match

Hi All,
I would like to find out ,is there any way to ignore case while match
template in XSLT.




Thanks,
Sen

--~------------------------------------------------------------------
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-***@lists.mulberrytech.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-***@lists.mulberrytech.com>
--~--
Syd Bauman
2008-10-01 12:38:31 UTC
Permalink
I would like to find out ,is there any way to ignore case while
match template in XSLT.
In some theoretical sense, the short answer is "no". XML is case
sensitive, and thus a <mix> is simply a different element than a
<Mix>. However, XPath (and thus XSLT) is perfectly capable of
matching more than one element name at once:
<xsl:template match=" mix | Mix "> ... </xsl:template>
or performing string manipulation inside a predicate in a match,
which is what Scott Trenda's solution takes advantage of:

XSLT 2.0
---- ---
<xsl:template match="*[ lower-case( local-name() ) = 'mix']">

XSLT 1.0
---- ---
<xsl:template match="*[ translate( local-name(),
'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
'abcdefghijklmnopqrstuvwxyz'
) = 'mix']">


--~------------------------------------------------------------------
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-***@lists.mulberrytech.com>
--~--
Ruud Grosmann
2008-10-01 12:49:31 UTC
Permalink
Post by Syd Bauman
XSLT 1.0
---- ---
<xsl:template match="*[ translate( local-name(),
'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
'abcdefghijklmnopqrstuvwxyz'
) = 'mix']">
Of course you don't need to translate all characters; maybe this one
speeds the style sheet up:
<xsl:template match="*[ translate( local-name(),'MIX','mix') = 'mix']">

regards, Ruud

--~------------------------------------------------------------------
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-***@lists.mulberrytech.com>
--~--
David Carlisle
2008-10-01 13:02:17 UTC
Permalink
Post by Syd Bauman
<xsl:template match="*[ lower-case( local-name() ) = 'mix']">
<xsl:template match="Mix|mix">
etc

while you can do that it's often not really convenient as you have to do
the same more or less everywhere

<xsl:template match="*[ lower-case( local-name() ) = 'mix']">
<xsl:value-of select="@*[ lower-case( local-name() ) = 'foo']">
..

etc

It may be better to consider a two stage process, first normalize, then
transform.

<xsl:variable name="lc">
<xsl:apply-templates mode="lc"/>
</xsl:variable>

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

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


then

<xsl:template match="/">
<xsl:apply-templates select="$c/*"/>
</xsl:template>

then the rest of your code.


Then in your main body of code you can assume lower case names an duse
normal xpath syntax


<xsl:template match="min">
<xsl:value-of select="@foo">
..


David

________________________________________________________________________
The Numerical Algorithms Group Ltd is a company registered in England
and Wales with company number 1249803. The registered office is:
Wilkinson House, Jordan Hill Road, Oxford OX2 8DR, United Kingdom.

This e-mail has been scanned for all viruses by Star. The service is
powered by MessageLabs.
________________________________________________________________________

--~------------------------------------------------------------------
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-***@lists.mulberrytech.com>
--~--
Andrew Welch
2008-10-01 13:15:11 UTC
Permalink
Post by David Carlisle
It may be better to consider a two stage process, first normalize, then
transform.
<xsl:variable name="lc">
<xsl:apply-templates mode="lc"/>
</xsl:variable>
<xsl:template match="*" mode="lc">
<xsl:element name="{lower-case(local-name())}
namespace="{namespace-uri(.)}">
(missing the mode there: <xsl:apply-templates select="@*,node()" mode="lc"/>)

The other way of lowercasing everything (if you are using Java) is to
use an XMLFilter which sits between the XMLReader and the
TransformerHandler.

Using a two-passes in the XSLT is much easier, while the XMLFilter
approach would be preferable where performance is an issue.
--
Andrew Welch
http://andrewjwelch.com
Kernow: http://kernowforsaxon.sf.net/

--~------------------------------------------------------------------
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-***@lists.mulberrytech.com>
--~--
Colin Paul Adams
2008-10-01 13:18:25 UTC
Permalink
Post by Syd Bauman
<xsl:template match="*[ lower-case( local-name() ) = 'mix']">
<xsl:template match="Mix|mix">
David> etc

David> while you can do that it's often not really convenient as
David> you have to do the same more or less everywhere

David> <xsl:template match="*[ lower-case( local-name() ) =
David> 'mix']"> <xsl:value-of select="@*[ lower-case( local-name()
David> ) = 'foo']"> ..

David> etc

David> It may be better to consider a two stage process, first
David> normalize, then transform.

Very sensible, although calling lower-case() is not actually
guaranteed to normalize - for instance, lower casing the German word
ESSEN cannot be done with the lower-case() function - the later will
produce essen (I shan't attempt to type the proper lower-cased version
in an email - i don't think I'm set up for non-ascci :-( ).
--
Colin Adams
Preston Lancashire

--~------------------------------------------------------------------
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-***@lists.mulberrytech.com>
--~--
Michael Kay
2008-10-01 13:40:27 UTC
Permalink
Post by Colin Paul Adams
Very sensible, although calling lower-case() is not actually
guaranteed to normalize - for instance, lower casing the
German word ESSEN cannot be done with the lower-case()
function - the later will produce essen
Wir essen heute abend, eßen tut mann nicht.

You're right in general, but chose a bad example. German ß always
capitalises as SS, as does ss. But in this case, whether it's the city or
the verb to eat, it's always "ss" in lower-case.

Michael Kay
http://www.saxonica.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-***@lists.mulberrytech.com>
--~--
David Carlisle
2008-10-01 13:50:39 UTC
Permalink
You're right in general, but chose a bad example. German ß always
capitalises as SS
Incidentally do you know why unicode 5.1 added a new codepoint for an
uppercase sharp s, I assumed when I saw its name that it would render
as SS but make upper/lowercase easier as it remained a
character-for-character operation (TeX fonts have had an SS character
for this reason for years) but I just checked on
http://www.unicode.org/charts/PDF/U1E00.pdf
and U+1E9E is shown as a large version of the sharp s (beta-like)
letter.

David

________________________________________________________________________
The Numerical Algorithms Group Ltd is a company registered in England
and Wales with company number 1249803. The registered office is:
Wilkinson House, Jordan Hill Road, Oxford OX2 8DR, United Kingdom.

This e-mail has been scanned for all viruses by Star. The service is
powered by MessageLabs.
________________________________________________________________________

--~------------------------------------------------------------------
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-***@lists.mulberrytech.com>
--~--
Michael Kay
2008-10-01 14:50:45 UTC
Permalink
Post by David Carlisle
Incidentally do you know why unicode 5.1 added a new
codepoint for an uppercase sharp s,
I do now ;=)

http://std.dkuug.dk/jtc1/sc2/wg2/docs/n3227.pdf

Michael Kay
http://www.saxonica.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-***@lists.mulberrytech.com>
--~--

Loading...