Functions.xsl - Eonic/ProteanCMS GitHub Wiki

replace-string

<xsl:call-template name="replace-string">
   <xsl:with-param name="replace">-</xsl:with-param>
   <xsl:with-param name="with">_</xsl:with-param>
   <xsl:with-param name="text">
     <xsl:value-of select="$ref"/>
   </xsl:with-param>
</xsl:call-template>

truncateString

Returns a string. The First argument is the string to be truncated. The Second argument is the maximum character length that the string is to be truncated to. This function Truncates the string to last whole word and adds ellipses on to the end -->

<xsl:call-template name="truncateString">
    <xsl:with-param name="string">
	<xsl:value-of select="OurNode/node()"/>
     </xsl:with-param>
     <xsl:with-param name="length" select="'500'"/>
</xsl:call-template>

cleanXhtml

this passes html through XSLT to rebuild the nodes and you can apply a cleanXhtml template to any specific match to change it. Really handy if you want to fix something output in TinyMCE

<xsl:apply-templates select="./node()" mode="cleanXhtml"/>

i.e. this makes all tables responsive

  <xsl:template match="table" mode="cleanXhtml">
    <div class="table-responsive">
      <xsl:element name="{name()}">
        <!-- process attributes -->
        <xsl:for-each select="@*">
          <!-- remove attribute prefix (if any) -->
          <xsl:attribute name="{name()}">
            <xsl:value-of select="." />
          </xsl:attribute>
        </xsl:for-each>
        <xsl:apply-templates mode="cleanXhtml"/>
      </xsl:element>
    </div>
  </xsl:template>

#flattenXhtml Sometimes, the data is stored in a Formatted Text field with xHTML,However when you are outputting you want want a plain text string. These templates run through an xHTML nodeset() but keeping basic inline styles. Ignore some tags like img, br, hr that don't contain plaintext.

<xsl:apply-templates select="ms:node-set($content)" mode="flattenXhtml"/>


⚠️ **GitHub.com Fallback** ⚠️