How to translate to uppercase some text
Here should go questions about transforming XML with XSLT and FOP.
-
- Posts: 2
- Joined: Wed Aug 21, 2013 5:25 pm
How to translate to uppercase some text
Hi, I'm an Oxygen user for about a year.
I never posted on this forum before because I've always found all the answers I needed and I am very grateful for this.
Now I was trying to translate some part of text from lowercase to uppercase.
It's embarrassing
but I can't figure out how to select just the string I need to translate.
Here an example of the file I'm working on:
I need to translate to uppercase the text tagged as "small", like this:
And this is the XSLT I was trying to apply:
This is obviously transforming all the text in uppercase.
How can I make it work only for the text tagged as "small"?
I spent some days trying to understand better XSLT and XPath
but I just can't figure it out.
Thanks a lot!
I never posted on this forum before because I've always found all the answers I needed and I am very grateful for this.

Now I was trying to translate some part of text from lowercase to uppercase.
It's embarrassing

Here an example of the file I'm working on:
Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Lorem ipsum</title>
</head>
<body>
<p>Lorem <small>ipsum</small> dolor sit amet, consectetur adipiscing elit. Integer ullamcorper.</p>
<p>Lorem ipsum dolor sit <small>amet</small>, consectetur adipiscing elit. Integer ullamcorper.</p>
</body>
</html>
Code: Select all
<p>Lorem <small>IPSUM</small> dolor sit amet, consectetur adipiscing elit. Integer ullamcorper.</p>
<p>Lorem ipsum dolor sit <small>AMET</small>, consectetur adipiscing elit. Integer ullamcorper.</p>
And this is the XSLT I was trying to apply:
Code: Select all
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:variable name="smallCase" select="'abcdefghijklmnopqrstuvwxyz'"/>
<xsl:variable name="upperCase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="text()">
<xsl:value-of select="translate(., $smallCase, $upperCase)"/>
</xsl:template>
</xsl:stylesheet>
How can I make it work only for the text tagged as "small"?
I spent some days trying to understand better XSLT and XPath

Thanks a lot!
-
- Posts: 2879
- Joined: Tue May 17, 2005 4:01 pm
Re: How to translate to uppercase some text
Hi,
This stylesheet does what you want, it copies everything and translates to uppercase the text tagged as "small" (including nested elements). This uses two template modes, one for normal copy (copy) and one for the copy with uppercase (uppercase).
Regards,
Adrian
This stylesheet does what you want, it copies everything and translates to uppercase the text tagged as "small" (including nested elements). This uses two template modes, one for normal copy (copy) and one for the copy with uppercase (uppercase).
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:copy>
<xsl:apply-templates mode="copy" select="@*"/>
<xsl:apply-templates mode="copy"/>
</xsl:copy>
</xsl:template>
<xsl:template match="xhtml:small" mode="copy">
<xsl:message>123</xsl:message>
<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>
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service