xsl-list
[Top] [All Lists]

Re: [xsl] Troublshooting XSLT replace()

2013-12-03 15:33:02
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.

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--