Transform XSLT URL

1

I want to transform a url from xslt with this format:

[sitio]/PublishingImages/[nombreimagen].jpg

to this other:

[sitio]/PublishingImages/_t/[nombreimagen]_jpg.jpg

At first try to use replace, but you can not use it in version 1.0 so try it by other means trying to use this template:

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

Calling after the template like this:

<xsl:variable name="primerreplace">
    <xsl:call-template name="string-replace">
        <xsl:with-param name="text" select="$ImageUrl" />
        <xsl:with-param name="pattern" select="PublishingImages" />
        <xsl:with-param name="replace-with" select="PublishingImages/_t" />
    </xsl:call-template>
</xsl:variable>                            
<xsl:variable name="segundoreplace">
    <xsl:call-template name="string-replace">
        <xsl:with-param name="text" select="$primerreplace" />
        <xsl:with-param name="pattern" select=".jpg" />
        <xsl:with-param name="replace-with" select="_jpg.jpg" />
    </xsl:call-template>
</xsl:variable> 
<xsl:value-of select="$segundoreplace">

But when loading the Web-Part I have the following error:

XSLT compile error.
 at NPS.Styler.Webparts.Styler.b__0() at Microsoft.SharePoint.SPSecurity.<>c__DisplayClass4.b__2() at Microsoft.SharePoint.Utilities.SecurityContext.RunAsProcess(CodeToRunElevated secureCode) at Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(WaitCallback secureCode, Object param) at Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(CodeToRunElevated secureCode) at NPS.Styler.Webparts.Styler.get_XSLTDoc() at NPS.Styler.Webparts.Styler.GetHtmlXMLFormat()

I'm probably doing something wrong.

    
asked by Carlos Bustamante Campo 26.10.2016 в 14:05
source

1 answer

2

You have to put the string arguments in quotation marks and declare the variable ImageUrl. (Thanks to @ Tim-C .)

Assuming that the XML has the following form:

<?xml version="1.0" encoding="UTF-8"?>
<document>
    <URL>[sitio]/PublishingImages/[nombreimagen].jpg</URL>
</document>

This would work:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

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

    <xsl:template match="URL">
        <xsl:variable name="ImageUrl" select="." />
    <xsl:variable name="primerreplace">
        <xsl:call-template name="string-replace">
            <xsl:with-param name="text" select="$ImageUrl" />
            <xsl:with-param name="pattern" select="'PublishingImages'" />
            <xsl:with-param name="replace-with" select="'PublishingImages/_t'" />
        </xsl:call-template>
    </xsl:variable>                            
    <xsl:variable name="segundoreplace">
        <xsl:call-template name="string-replace">
            <xsl:with-param name="text" select="$primerreplace" />
            <xsl:with-param name="pattern" select="'.jpg'" />
            <xsl:with-param name="replace-with" select="'_jpg.jpg'" />
        </xsl:call-template>
    </xsl:variable> 
    <xsl:value-of select="$segundoreplace" />
    </xsl:template>

</xsl:stylesheet>
    
answered by 07.11.2016 / 18:57
source