xsl-list
[Top] [All Lists]

Re: copy and translate an element and its children

2003-07-03 12:02:19
Matthew L. Avizinis wrote:

Hello,
 I am currently using
               <xsl:variable name="short-title">
                     <xsl:for-each select="title/node()">
                       <xsl:if test="not(position()=1)">
                         <xsl:copy-of select="."/>
                       </xsl:if>
                     </xsl:for-each>
               </xsl:variable>
This copies all nodes unchanged.

Isn't it better to use
 <xsl:variable name="short-title"
    select="title/node()[position() &gt; 1]"/>
Avoids copying.

However, what I'd now like to be able to do is create the same variable but with the contents of each node copied translated to uppercase. Is there an elegant way to do this?
thanks,

Well, try
 <xsl:variable name="short-title">
   <xsl:apply-templates
     select="title/node()[position() &gt; 1]"
     mode="upcase"/>
 </xsl:variable>
 ...
 <xsl:template match="*|@*" mode="upcase">
   <xsl:copy>
     <xsl:apply-templates select="*|@*"
         mode="upcase"/>
   <xsl:copy>
 </xsl:template>

 <xsl:template match="text()" mode="upcase">
   <xsl:value-of select="translate(.,'abcde...','ABCDE...')"/>
 </xsl:template>
Beware, untested.

Complete the mapping in the translate() to your needs (you might
want to upcase non-ASCII too).

J.Pietschmann



XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



<Prev in Thread] Current Thread [Next in Thread>