Convert lower to upper case for XML element without any attributes
Posted: Thu Jul 28, 2016 7:32 pm
Example XML:
No I am trying to transform to
so I am trying to convert the value of element without attribute to upper case, so if you see the element "title" is having attribute "lang", so the value for this element should not be converted to upper case.
I got anothe code bit from Oxygen but that is converting all value to upper case. I tried my best but not able to achieve what I want , so can you please help me or advice if at all it is possible?
Code I am using :
Thanks
Sreejit
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<bookstore>
<book>
<title lang="in">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>
<book category="children">
<title lang="en">Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
<book>
<title lang="en">XQuery Kick Start</title>
<author>James McGovern</author>
<author>Per Bothner</author>
<author>Kurt Cagle</author>
<author>James Linn</author>
<author>Vaidyanathan Nagarajan</author>
<year>2003</year>
<price>49.99</price>
</book>
<book category="web">
<title lang="en">Learning XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>39.95</price>
</book>
</bookstore>
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<bookstore>
<book>
<title lang="in">Everyday Italian</title>
<author>GIADA DE LAURENTIIS</author>
<year>2005</year>
<price>30.00</price>
</book>
<book category="children">
<title lang="en">Harry Potter</title>
<author>J K. ROWLING</author>
<year>2005</year>
<price>29.99</price>
</book>
<book>
<title lang="en">XQuery Kick Start</title>
<author>JAMES MCGOVERN</author>
<author>PER BOTHNER</author>
<author>KURT CAGLE</author>
<author>JAMES LINN</author>
<author>VAIDYANATHAN NAGARAJAN</author>
<year>2003</year>
<price>49.99</price>
</book>
<book category="web">
<title lang="en">Learning XML</title>
<author>ERIK T. RAY</author>
<year>2003</year>
<price>39.95</price>
</book>
</bookstore>
I got anothe code bit from Oxygen but that is converting all value to upper case. I tried my best but not able to achieve what I want , so can you please help me or advice if at all it is possible?
Code I am using :
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xhtml="http://www.w3.org/1999/xhtml">
<xsl:variable name="smallCase" select="'abcdefghijklmnopqrstuvwxyz'"/>
<xsl:variable name="upperCase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>
<!-- Match document -->
<xsl:template match="/">
<xsl:apply-templates mode="copy" select="."/>
</xsl:template>
<!-- Deep copy template -->
<xsl:template match="*|text()|@*" mode="copy">
<xsl:apply-templates mode="uppercase" select="."/>
</xsl:template>
<!-- Deep copy uppercase -->
<xsl:template match="*|@*" mode="uppercase">
<xsl:copy>
<xsl:apply-templates mode="uppercase" select="@*"/>
<xsl:apply-templates mode="uppercase"/>
</xsl:copy>
</xsl:template>
<xsl:template match="text()" mode="uppercase">
<xsl:value-of select="translate(., $smallCase, $upperCase)"/>
</xsl:template>
</xsl:stylesheet>
Sreejit