hi, I need select a node like "//element[@attr='value']", but the "attr" in document can be "Attr", "ATtr" and so on, as well as the "value".
I know I can select element with case insensitive using translate function like "//*[translate(name(), 'abc','ABC')='ABC']"
But how can I let it work with attribute and its value?
Can anybody help me? Thanks.

Recommended Answers

All 2 Replies

Hello to XML user

xml for testing

<?xml version="1.0"?>
<root>
<element attr='Abc'/>
<element Attr='ABc'/>
<element ATtr='abC'/>
<element attr='ABC'/>
<element attr='AbC'/>
<element class='AbC'/>
</root>





<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes" method="xml"/>
<xsl:template match="/">
<root>
    <xsl:apply-templates select="//element"/>
    </root>
</xsl:template>



<xsl:template match="element">
<erg>
<xsl:choose>
<xsl:when test="translate(name(@*),'art','ART')='ATTR'">
<xsl:value-of select="concat(@*,' ',translate(@*,'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ'))"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat(name(@*),' no change')"/>
</xsl:otherwise>
</xsl:choose>

</erg>   
</xsl:template>
</xsl:stylesheet>

is a problem when not use attr eg class
then i use

xsl:choose

translate(@*,'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ')

all Attribute

result




<?xml version='1.0' ?>
<root>
  <erg>Abc ABC</erg>
  <erg>ABc ABC</erg>
  <erg>abC ABC</erg>
  <erg>ABC ABC</erg>
  <erg>AbC ABC</erg>
  <erg>class no change</erg>
</root>

Helmut Hagemann

on my, thank you very much! you are so kindhearted!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.