Re: [xsl] Creating strings with apos and replacing

Subject: Re: [xsl] Creating strings with apos and replacing
From: "David Carlisle d.p.carlisle@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 13 May 2025 19:15:11 -0000
On Tue, 13 May 2025 at 20:04, dvint dvint@xxxxxxxxx <
xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:

> Trplle apos does the trick for defining the variable, but doesn't work for
> the replace().
>

to get a ' into an xpath string you either need a single ' in as "-quoted
string or a double '' in a '=quoted string.
Using & apos; doesn't help as xml entities are expanded before the xpath is
parsed.

so you can use "foo 'example' bar"     or 'foo ''example' bar'  to get the
string foo 'example' bar

David


>
>
> Sent from my Verizon, Samsung Galaxy smartphone
>
>
> -------- Original message --------
> From: "Martin Honnen martin.honnen@xxxxxx" <
> xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
> Date: 5/13/25 11:51 AM (GMT-08:00)
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: Re: [xsl] Creating strings with apos and replacing
>
>
> On 13/05/2025 20:40, dvint@xxxxxxxxx wrote:
> > My main question is the correct way to use replace() to remove special
> > characters and spaces that appear in document titles. Some I just want
> > to remove and others I want to translate to something else.
> >
> > I have this much working
> >
> > <xsl:function name="ping:gen_id">
> >     <xsl:param name="INSTRING"/>
> >     <xsl:value-of select="translate(replace(lower-case($INSTRING), '
> > ', '_'),
> >     ':()','')"/>
> > </xsl:function>
> >
> > To the replace I wanted to add the ' character to replace with
> > nothing. I tried adding \' \\' &apo; &apos;&apos; to no avail.
>
>
> In XPath 2.0 and later you can use two single quotes inside a single
> quoted string e.g. ':()''' or ''''.
>
> >
> > This iss a sample of a string I'm trying to modify:
> >
> > "Step 9: Create the application's resource access grant"
> >
> > So I asked coPilot what should be done and it came up with:
> >
> > <xsl:template match="/">
> >     <xsl:variable name="inputString" select="'This is a string with a
> > single quote: 'example''" />
> >     <xsl:variable name="outputString" select="translate($inputString,
> > &apos;&apos;, '')" />
> >     <xsl:value-of select="$outputString" />
> > </xsl:template>
> >
> > This throws a different error around creating the inputString.
> >
> > Unexpected token name "example" beyond end of expression
> >
> > Which leads to the other part of my question about how you would
> > create a string variable with an &apos; in the content. I imagine it
> > will be the same answer, but wanted to post this for completion of the
> > question.
> >
> >
>   'This is a string with a single quote: ''example'''
>
>
> XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
> EasyUnsubscribe <http://lists.mulberrytech.com/unsub/xsl-list/2739265> (by
> email <>)

Current Thread