Re: [xsl] Troublshooting XSLT replace()

Subject: Re: [xsl] Troublshooting XSLT replace()
From: Nathan Tallman <ntallman@xxxxxxxxx>
Date: Tue, 3 Dec 2013 16:48:32 -0500
Thank you, Graydon. I am cleaning up a huge stack of XMLs;
unfortunately I cannot use lower() because there may be other text in
<unitdate> that needs to remain capitalized.


On Tue, Dec 3, 2013 at 4:32 PM, Graydon <graydon@xxxxxxxxx> wrote:
> On Tue, Dec 03, 2013 at 04:05:04PM -0500, Nathan Tallman scripsit:
>> I spoke to early, o omniscient one. <unittitle> can contain child
>> nodes that are being stripped. I tried <xsl:copy-of> instead of
>> <xsl:value-of>, but they're still being stripped.
>> The desired result is to keep all child nodes, remove trailing
>> punctuation, replace Undated/undated, and replace Circa/circa.
>> Is there a way to do this with the identity template, without using *|node() ?
> Kinda hard for it to be the identity template if you _don't_ use node()|@*.
> <xsl:template match="node()|@*">
>         <xsl:copy>
>             <xsl:apply-templates select="node()|@*" />
>         </xsl:copy>
> </xsl:template>
> <xsl:template match="text()[ancestor::unittittle]">
>     <xsl:value-of
>         select="replace(replace(replace(.,'\p{P}+$',''),'Undated','undated'),'Circa','circa')"
>          />
> </xsl:template>
> I'd be tempted to use "lower()" instead of the outer two replaces if you know you don't need to keep some other upper-case letters.
> -- Graydon, who thinks there's a general rule with XSLT; if your code is turning into a vast tentacular mass of cases, there's probably something you missed.

Current Thread