Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Transformation of text with nested elements

From: "Dimitre Novatchev" <dimitren@---.---.-->
To: NULL
Date: 5/11/2005 7:15:00 AM
"Mathias Harbeck" <harbeck@g...> wrote in message 
news:1h5wmfbcwnbxv.16emk3pydluj7.dlg@4......
> Hi,
>
> i have a xml passage that looks like this:
>
> <title>this is a <super>title</super> with superscript <sub>and</sub>
> subscript.</title>
>
> The transformation should do the following things:
> - preservere the structure
> - change *all* text to uppercase
>
> The result should be the following:
>
> <title>THIS IS A <super>TITLE</super> WITH SUPERSCRIPT <sub>AND</sub>
> SUBSCRIPT.</title>
>
> I searched the whole day for a working solution but couldn't find 
> anything.
> This is what i am able to do up to now:
> - uppercase the whole string but loose the nested elements ("THIS IS A
> TITLE WITH SUPERSCRIPT AND SUBSCRIPT"; simply by matching "title" and 
> using
> "translate()" on ".")
> - preserver the structure and uppercase the nested elements ("This is a
> <super>TITLE</super> with superscript <sub>AND</sub> subscript.</title>";
> matching "title", calling "apply-templates", matching "sub" and "super",
> inserting sub/super-elements and using "translate()" on ".").
>
> Has anyone an idea how a could realize this?
>
> TIA
> Mathias

Just override the identity rule like this:

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output omit-xml-declaration="yes" indent="yes"/>

 <xsl:variable name="lower" select=
  "'abcdefghijklmnopqrstuvwxyz'"/>

 <xsl:variable name="upper" 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(.,$lower,$upper)"/>
  </xsl:template>
</xsl:stylesheet>


There is no upper-case() function in XPath 1.0 -- it is part of XPath 2.0 
Functions and Operators, which is still a draft.

Cheers,
Dimitre Novatchev. 




transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent