XSLT - replace apostrophe with shielded output text

I am writing an XSLT template that should output a valid XML file for an XML Sitemap.

<url>
<loc>
    <xsl:value-of select="umbraco.library:NiceUrl($node/@id)"/>
</loc>
<lastmod>
    <xsl:value-of select="concat($node/@updateDate,'+00:00')"/>
</lastmod>
</url>

Unfortunately, the url that is displayed contains an apostrophe - / what-new.aspx

I need to hide 'to &apos;for the Google Sitemap. Unfortunately, every attempt I tried processes the string ` &apos;` ' ' as if it were `` '', which is invalid - upsets. Sometimes XSLT can make me angry.

Any ideas for the technique? (Suppose I can find a way around XSLT 1.0 templates and functions)

+3
source share
4 answers

, ' , &nbsp; ?

XSL &apos; &amp;apos;, / ( XSLT 2.0):

<xsl:template name="string-replace-all">
  <xsl:param name="text"/>
  <xsl:param name="replace"/>
  <xsl:param name="by"/>
  <xsl:choose>
    <xsl:when test="contains($text,$replace)">
      <xsl:value-of select="substring-before($text,$replace)"/>
      <xsl:value-of select="$by"/>
      <xsl:call-template name="string-replace-all">
        <xsl:with-param name="text" select="substring-after($text,$replace)"/>
        <xsl:with-param name="replace" select="$replace"/>
        <xsl:with-param name="by" select="$by"/>
      </xsl:call-template>
    </xsl:when>
    <xsl:otherwise>
      <xsl:value-of select="$text"/>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

:

<loc>
  <xsl:call-template name="string-replace-all">
    <xsl:with-param name="text" select="umbraco.library:NiceUrl($node/@id)"/>
    <xsl:with-param name="replace" select="&apos;"/>
    <xsl:with-param name="by" select="&amp;apos;"/>
  </xsl:call-template>
</loc>

&apos; XSL '. &amp;apos; &apos;.

+9

URL , umbraco NiceUrl.

/umbracoSettings.config

, NiceUrls, :

<urlReplacing>
    ...
    <char org="'"></char>     <!-- replace ' with nothing -->
    ...
</urlReplacing>

. "org" , :

<char org="+">plus</char> <!-- replace + with the word plus -->
+1

Have you tried setting disable-output-escaping to your xsl: value-of element:

<xsl:value-of disable-output-escaping="yes" select="umbraco.library:NiceUrl($node/@id)"/>

Actually - this is probably the opposite of what you want.

How to wrap xsl value: value in xsl text element:

<xsl:text><xsl:value-of select="umbraco.library:NiceUrl($node/@id)"/></xsl:text>

Maybe you should try translating 'to&amp;apos;

0
source

This will work, you just need to modify TWO params as below

<xsl:with-param name="replace">&apos;</xsl:with-param>
<xsl:with-param name="by" >AnyString</xsl:with-param>
0
source

Source: https://habr.com/ru/post/1712182/


All Articles