You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Lincoln Mitchell <li...@interfaces-n-creatives.com> on 2007/08/22 09:11:34 UTC

degree symbol from wordml

I am trying to output a degree symbol from wordML.
It is entered in word as the symbol  "Alt+0176" ASCII (Decimal).
Which in WordML translates to:
<w:t>°</w:t>

Now, I was hoping to see:
<w:t>&#176</w:t>
And catch it with...
<!ENTITY deg "&#176;">

So what do I do now?
Is the trick putting the right encoder in the serializer?
Or create a template that matches "°" and replaces with "&deg;"?
Or is this a question for the XSL list?

TIA

Linc


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


RE: degree symbol from wordml

Posted by Lincoln Mitchell <li...@interfaces-n-creatives.com>.
This is the code I now have which as mentioned outputs in HTML as &amp;deg;
not &deg;:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [ 
	<!ENTITY nbsp "&#160;">
	<!ENTITY deg "&#176;">
	<!ENTITY amp "&#38;">]>
<xsl:stylesheet version="1.0" 
    xmlns:xalan="http://xml.apache.org/xalan"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/1999/xhtml">
 <xsl:template match="/">
 <html>
 	<body>
    	<xsl:apply-templates/>
    </body>
 </html>
 </xsl:template>
  <xsl:template match="text()">
  	<xsl:call-template name="degree"/>
  </xsl:template>

<xsl:template name="degree">
	<xsl:param name="text" select="."/>
    <xsl:choose>
    	<xsl:when test="contains($text, '°')">
        	<xsl:value-of select="substring-before($text,'°')"/>
            <xsl:text>&amp;deg;</xsl:text>
            <xsl:call-template name="degree">
            	<xsl:with-param name="text"
select="substring-after($text,'°')"/>
            </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
        	<xsl:value-of select="$text"/>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>
 
</xsl:stylesheet>

> -----Original Message-----
> From: Joerg Heinicke [mailto:joerg.heinicke@gmx.de]
> Sent: Thursday, 23 August 2007 12:29 PM
> To: Cocoon Users List
> Cc: lincoln@interfaces-n-creatives.com
> Subject: Re: degree symbol from wordml
> 
> (Please keep responses to the list even if Cocoon users list might not
> be the best list for this topic.)
> 
> First your XSLT is parsed by an XML parser and the entity &deg; gets
> resolved to the character reference &#176; which gets resolved to the
> character °. So for the XSLT processor it is actually
> translate(.,'°','°').
> 
> Second I can not really explain the difference in behavior of
> serializing ° and the non-breaking space character (to which &nbsp; gets
> resolved). Both are HTML 4 entities [1]. I'm not aware of any special
> entities in the XSLT spec. So it might be just an XSLT processor behavior.
> 
> Third, do you have a problem with °? It should also work.
> 
> Fourth, the correct way of writing a entity reference to the output is
> by escaping the ampersand: &amp;deg; This is now not parsed to one
> character °, but to 5 characters &, d, e, g and - guess what - ;. You
> can't do this replacement with the translate function anymore but you
> have to switch to a recursive template [2].
> 
> Joerg
> 
> [1] http://www.w3.org/TR/html401/sgml/entities.html#h-24.2
> [2] http://www.dpawson.co.uk/xsl/sect2/replace.html
> 
> 
> On 22.08.2007 22:11 Uhr, lincoln@interfaces-n-creatives.com wrote:
> > Thanks for the typo.
> > I am just trying to convert "°" to the HTML entity equivalent "&deg"
> > After further research my approach is currently to use this xsl:
> > <?xml version="1.0"?>
> >    <!DOCTYPE xsl:stylesheet [
> >     <!ENTITY nbsp "&#160;">
> >     <!ENTITY deg "&#176;">
> >     ]>
> > ---
> > <xsl:stylesheet version="1.0"
> >   xmlns:xalan="http://xml.apache.org/xalan"
> >   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> >   xmlns="http://www.w3.org/1999/xhtml">
> >  <xsl:template match="/">
> >  <html>
> >     <body>
> >         <xsl:apply-templates/>
> >     </body>
> >  </html>
> >  </xsl:template>
> >   <xsl:template match="text()" priority="-1">
> >       <xsl:value-of select="translate(.,'°','&deg;')"/>
> >   </xsl:template>
> > </xsl:stylesheet>
> > ---
> >
> > But "&deg;" doesn't end up in my HTML, it stays as "°".
> > However, it works with &nbsp; ie:
> > <xsl:value-of select="translate(.,'°','&nbsp;')"/>
> >
> > So what's the difference between the 2 entities and how can I resolve
> it?
> >
> > Linc
> >
> > Quoting Joerg Heinicke <jo...@gmx.de>:
> >
> >> On 22.08.2007 3:11 Uhr, Lincoln Mitchell wrote:
> >>
> >>> I am trying to output a degree symbol from wordML.
> >>> It is entered in word as the symbol  "Alt+0176" ASCII (Decimal).
> >>> Which in WordML translates to:
> >>> <w:t>°</w:t>
> >>>
> >>> Now, I was hoping to see:
> >>> <w:t>&#176</w:t>
> >>
> >> Just that (but with a semi-colon at the end: &#176;) should be
> >> sufficient. But you say you have the ° already in the WordML. Why do
> >>  you want to handle it at all in your XSLT? What's wrong with
> >> <w:t>°</w:t> compared to <w:t>&#176;</w:t>?
> >>
> >> Joerg


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: degree symbol from wordml

Posted by Joerg Heinicke <jo...@gmx.de>.
(Please keep responses to the list even if Cocoon users list might not 
be the best list for this topic.)

First your XSLT is parsed by an XML parser and the entity &deg; gets 
resolved to the character reference &#176; which gets resolved to the 
character °. So for the XSLT processor it is actually translate(.,'°','°').

Second I can not really explain the difference in behavior of 
serializing ° and the non-breaking space character (to which &nbsp; gets 
resolved). Both are HTML 4 entities [1]. I'm not aware of any special 
entities in the XSLT spec. So it might be just an XSLT processor behavior.

Third, do you have a problem with °? It should also work.

Fourth, the correct way of writing a entity reference to the output is 
by escaping the ampersand: &amp;deg; This is now not parsed to one 
character °, but to 5 characters &, d, e, g and - guess what - ;. You 
can't do this replacement with the translate function anymore but you 
have to switch to a recursive template [2].

Joerg

[1] http://www.w3.org/TR/html401/sgml/entities.html#h-24.2
[2] http://www.dpawson.co.uk/xsl/sect2/replace.html


On 22.08.2007 22:11 Uhr, lincoln@interfaces-n-creatives.com wrote:
> Thanks for the typo.
> I am just trying to convert "°" to the HTML entity equivalent "&deg"
> After further research my approach is currently to use this xsl:
> <?xml version="1.0"?>
>    <!DOCTYPE xsl:stylesheet [
>     <!ENTITY nbsp "&#160;">
>     <!ENTITY deg "&#176;">
>     ]>
> ---
> <xsl:stylesheet version="1.0"
>   xmlns:xalan="http://xml.apache.org/xalan"
>   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>   xmlns="http://www.w3.org/1999/xhtml">
>  <xsl:template match="/">
>  <html>
>     <body>
>         <xsl:apply-templates/>
>     </body>
>  </html>
>  </xsl:template>
>   <xsl:template match="text()" priority="-1">
>       <xsl:value-of select="translate(.,'°','&deg;')"/>
>   </xsl:template>
> </xsl:stylesheet>
> ---
> 
> But "&deg;" doesn't end up in my HTML, it stays as "°".
> However, it works with &nbsp; ie:
> <xsl:value-of select="translate(.,'°','&nbsp;')"/>
> 
> So what's the difference between the 2 entities and how can I resolve it?
> 
> Linc
> 
> Quoting Joerg Heinicke <jo...@gmx.de>:
> 
>> On 22.08.2007 3:11 Uhr, Lincoln Mitchell wrote:
>>
>>> I am trying to output a degree symbol from wordML.
>>> It is entered in word as the symbol  "Alt+0176" ASCII (Decimal).
>>> Which in WordML translates to:
>>> <w:t>°</w:t>
>>>
>>> Now, I was hoping to see:
>>> <w:t>&#176</w:t>
>>
>> Just that (but with a semi-colon at the end: &#176;) should be  
>> sufficient. But you say you have the ° already in the WordML. Why do 
>>  you want to handle it at all in your XSLT? What's wrong with  
>> <w:t>°</w:t> compared to <w:t>&#176;</w:t>?
>>
>> Joerg

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: degree symbol from wordml

Posted by Joerg Heinicke <jo...@gmx.de>.
On 22.08.2007 3:11 Uhr, Lincoln Mitchell wrote:

> I am trying to output a degree symbol from wordML.
> It is entered in word as the symbol  "Alt+0176" ASCII (Decimal).
> Which in WordML translates to:
> <w:t>°</w:t>
> 
> Now, I was hoping to see:
> <w:t>&#176</w:t>

Just that (but with a semi-colon at the end: &#176;) should be 
sufficient. But you say you have the ° already in the WordML. Why do you 
want to handle it at all in your XSLT? What's wrong with <w:t>°</w:t> 
compared to <w:t>&#176;</w:t>?

Joerg

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: degree symbol from wordml

Posted by Baptiste Placé <bo...@free.fr>.
Lincoln,

I think this is XSLT related and you may find your answer here :
http://www.dpawson.co.uk/xsl/sect2/N7150.html#d10368e49
Anyway you will know how to match it in pure xslt :)

Baptiste.

Lincoln Mitchell a écrit :
> I am trying to output a degree symbol from wordML.
> It is entered in word as the symbol  "Alt+0176" ASCII (Decimal).
> Which in WordML translates to:
> <w:t>°</w:t>
>
> Now, I was hoping to see:
> <w:t>&#176</w:t>
> And catch it with...
> <!ENTITY deg "&#176;">
>
> So what do I do now?
> Is the trick putting the right encoder in the serializer?
> Or create a template that matches "°" and replaces with "&deg;"?
> Or is this a question for the XSL list?
>
> TIA
>
> Linc
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
>
>   

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org