Re: [xsl] Asymmetric string handling with processing-instructions

Subject: Re: [xsl] Asymmetric string handling with processing-instructions
From: "Martin Honnen martin.honnen@xxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 14 Sep 2023 15:27:24 -0000
On 14.09.2023 16:05, Michael Mueller-Hillebrand
michael.mueller-hillebrand@xxxxxxxxx wrote:
>
> My bottom line: If you want to use saxon:get-pseudo-attribute(),
> because it is elegant and efficient, and it could be possible you have
> user content in processing instruction, you have two additional tasks:
>
> * When using xsl:processing-instruction or other ways to create
> processing instructions, make sure to escape the five XML characters
>
> * When accessing PI string values without saxon:get-pseudo-attribute,
> add an unescaping routine to avoid double escaped content.
>
> How do you deal with this asymmetry?
>

For the escaping in your sample, one way to ensure the ampersand is
escaped could be


 B B B  <xsl:template match="p">

 B B B B B B B  <xsl:processing-instruction name="my" select="'value=&quot;'
||
string() => serialize(map { 'method' : 'xml' }) || '&quot;'"/>

 B B B  </xsl:template>

Should also work for the less than sign but probably not for double quotes.

I was also playing with some attributes created on the fly to be
serialized but as standalone attributes can't be serialized that doesn't
work out; I am not sure whether creating an element with attributes on
the fly and then serializing it to use string processing on the
serialization result to get only the right attribute serialization is
too hacky.

Current Thread