Subject: Re: [xsl] Asymmetric string handling with processing-instructions From: "Michael Mueller-Hillebrand michael.mueller-hillebrand@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Fri, 15 Sep 2023 06:25:39 -0000 |
Thanks a lot for your feedback and thoughts, Martin, Special thanks for reminding me that a simple string can be treated/parsed as XML and there is no need for an element to use parse-xml-fragment(). When creating the text content of a processing instruction we have to decide which quotes to use around the pseudo attribute value and therefore handle this quote different in the content. We plan to use apostrophe and therefore would use ' for single quotes in content. We already do this in Java elsewhere and will use the same method in XSLT. Best regards,. - Michael From: Martin Honnen martin.honnen@xxxxxx <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Sent: Thursday, September 14, 2023 6:09 PM To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: Re: [xsl] Asymmetric string handling with processing-instructions On 14.09.2023 17:27, Martin Honnen martin.honnen@xxxxxx<mailto:martin.honnen@xxxxxx> wrote: On 14.09.2023 16:05, Michael Mueller-Hillebrand michael.mueller-hillebrand@xxxxxxxxx<mailto:michael.mueller-hillebrand@docufy .de> 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 <xsl:template match="p"> <xsl:processing-instruction name="my" select="'value="' || string() => serialize(map { 'method' : 'xml' }) || '"'"/> </xsl:template> Should also work for the less than sign but probably not for double quotes. For the string value using `parse-xml-fragment` should help e.g. <xsl:template match="processing-instruction(my)"> <p> <xsl:text>String: </xsl:text> <xsl:value-of select="string(.) => parse-xml-fragment()"/> </p> gives <p>String: value="Marks & Spencer PI"</p> XSL-List info and archive<http://www.mulberrytech.com/xsl/xsl-list> EasyUnsubscribe<http://lists.mulberrytech.com/unsub/xsl-list/3481519> (by email<>)
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Asymmetric string handlin, Martin Honnen martin | Thread | [xsl] Performance of link target se, Trevor Nicholls trev |
Re: [xsl] Asymmetric string handlin, Martin Honnen martin | Date | [xsl] Performance of link target se, Trevor Nicholls trev |
Month |