[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] Escaping Characters in replace()


Subject: Re: [xsl] Escaping Characters in replace()
From: Nathan Tallman <ntallman@xxxxxxxxx>
Date: Tue, 15 Oct 2013 16:06:52 -0400

Thank you, David!

On Tue, Oct 15, 2013 at 3:54 PM, David Carlisle <davidc@xxxxxxxxx> wrote:
> On 15/10/2013 20:31, Nathan Tallman wrote:
>>
>> Thank you, David and Ivan. It did, of course, work... I just had more
>> problems than I thought. The code you helped with, works in situations
>> like:
>>
>>      <unittitle>"The Atomic Bomb Foreshadowed: 1700 Years Ago".
>> 1947.</unittitle>
>>
>> However, I also have to account for situations like:
>>      <unittitle>
>>          <title render="doublequote">The Atomic Bomb Foreshadowed: 1700
>> Years Ago</title>. 1947.</unitdate>
>>      </unittitle>
>>
>> There are separate instructions that insert " before the title/text()
>> and ." after title/text(), which results in:
>>      "The Atomic Bomb Foreshadowed: 1700 Years Ago.". 1947.
>>
>> In this scenario, how can I get rid of the extraneous period? Should I
>> test for a unittitle/title that is immediately followed by a period?
>> If so, how would I do that? Testing on unittitle/title won't let me
>> change anything outside the node, like the extra period.
>>
>> Many, many thanks for your wisdom.
>>
>
>
> Don't match on text() unless you have to:
>> insert " before the title/text()
>
> in <title> blah <!-- stuff -->blah</title>
>
> there are two text nodes so if you are not careful and add " around
> title/text() you will get " blah ""blah" I'd so
>
> <xsl:template match="title[@render='doublequote">
>   <xsl:text>"</xsl:text>
>  <xsl:apply-templates/>
>  <xsl:text>"</xsl:text>
> </xsl:template>
>
> <xsl:template match="unititle">
>   <xsl:variable name="x">
>   <xsl:apply-templates/>
>  </xsl:variable>
>   <xsl:value-of select="replace($x,'&quot;\.','.&quot;')"/>
> </xsl:template>
>
>
> David
>
>
>
>
>
> --
> google plus: https:/profiles.google.com/d.p.carlisle


Current Thread