问题
I am using an XSLT stylesheet to create an Excel document from an XML file. One of the values that I am pulling in I want to display as upper case. How is this possible?
回答1:
XSLT 2.0 has fn:upper-case() and fn:lower-case() functions. However in case you are using of XSLT 1.0, you can use translate():
<xsl:template match="/">
<xsl:variable name="smallcase" select="'abcdefghijklmnopqrstuvwxyz'" />
<xsl:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'" />
<xsl:value-of select="translate(doc, $smallcase, $uppercase)" />
</xsl:template>
回答2:
You can use the translate()
function in XSLT 1.0:
<xsl:value-of select="translate(//some-xpath,
'abcdefghijklmnopqrstuvwxyz',
'ABCDEFGHIJKLMNOPQRSTUVWXYZ')" />
If you're lucky enough to have access to XSLT 2.0, you can use the upper-case()
function:
<xsl:value-of select="upper-case(//some-xpath)"/>
See the XPath function reference page for more details.
回答3:
XPath 2.0 has fn:upper-case(), which also does Unicode correct case mappings.
回答4:
Use an Assembly like this:
<msxsl:script implements-prefix="user" language="C#">
<!--{%assembly%}-->
<![CDATA[
public string ToUpper(string stringValue)
{
string result = String.Empty;
if(!String.IsNullOrEmpty(stringValue))
{
result = stringValue.ToUpper();
}
return result;
}
]]>
</msxsl:script>
Call it as follows: select="user:ToUpper(//root/path)"
This can be used in 1.0 or 2.0.
回答5:
The easiest and cleanest way to achieve case transforms is by the means of CSS.
build a class, like:
.upper { text-transform: uppercase; }
then use the class as span class:
<span class="upper">
<xsl:value-of select="myTextField" />
</span>
that's it :)
You can also use other transforms:
text-transform: capitalize | uppercase | lowercase | none | inherit
来源:https://stackoverflow.com/questions/1207098/xslt-stylesheet-changing-text-to-upper-case