Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XSLT - Ignore case while matching

Tags:

xslt

I have an XML "1.0" XSLT transformation where I need case insensitive matching. I am using the following to rename "my_col" to "renamed_col",

<xsl:template match="my_col">
    <renamed_col>
        <xsl:apply-templates select="@* | node()"/>
    </renamed_col>
</xsl:template>

This works fine if I use "my_col", but fails when I use "My_Col". I need to match this column irrespective of the letter case.

Any help would be greatly appreciated.

like image 463
Tejal Avatar asked Nov 26 '25 22:11

Tejal


2 Answers

Try this:

 <xsl:template match="*[ translate( local-name(),
                                         'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
                                         'abcdefghijklmnopqrstuvwxyz'
                                        ) = 'my_col']">
like image 95
Priyansh Goel Avatar answered Nov 28 '25 16:11

Priyansh Goel


The answer given by Priyansh Goel will cover all possible case variations (except with names that use characters other than those listed). However, if you know what variations to expect, you could make this simpler (and faster) by listing them explicitly, e.g.:

<xsl:template match="my_col | My_Col">
    <renamed_col>
        <xsl:apply-templates select="@* | node()"/>
    </renamed_col>
</xsl:template>
like image 31
michael.hor257k Avatar answered Nov 28 '25 15:11

michael.hor257k



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!