Subject: Re: [xsl] What is a bulletproof way to assign a variable this value: single quote, value of an element, single quote? From: "David Carlisle d.p.carlisle@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Mon, 13 May 2024 13:13:51 -0000 |
You need to specify what you want to happen. As written "string value between single quotes" then there is no error. If you want to specify that single quotes within the content are escaped in some way, you need to say what that should be xpath style doubling '' xml entity ref ' or ' %-escape %27 \ escape \' anything else... basically all of then can be done as concat("'",replace(.,"'","whatever the replacement is"),"'") On Mon, 13 May 2024 at 14:05, Roger L Costello costello@xxxxxxxxx < xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote: > Hi Folks, > > The value of $legacy-elmt is this element: > > <test>Hello, world</test> > > Create a variable which holds between single quotes the value of the > element that $legacy-elmt holds. Do this using a two-step process: > > <xsl:variable name="tmp-legacy-elmt-value" as="xs:string+"> > <xsl:text>'</xsl:text> > <xsl:value-of select="string($legacy-elmt)"/> > <xsl:text>'</xsl:text> > </xsl:variable> > > <xsl:variable name="legacy-elmt-name" as="xs:string"> > <xsl:value-of select="$tmp-legacy-elmt-value" separator=""/> > </xsl:variable> > > $legacy-elmt-value = 'Hello, world' > > That appears to work flawlessly, right? > > Not so fast. > > Suppose the value of $legacy-elmt is this element: > > <test>O'Neil</test> > > $legacy-elmt-value = 'O'Neil' > > That is an error (unmatched single quote). > > What is the best way to fix this error? > > /Roger
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] What is a bulletproof way, Martin Honnen martin | Thread | Re: [xsl] What is a bulletproof way, Peter Flynn peter@xx |
Re: [xsl] What is a bulletproof way, Martin Honnen martin | Date | Re: [xsl] What is a bulletproof way, Peter Flynn peter@xx |
Month |