Albert Jan Schot
 

Cleaning up HTML output

18

Jul

 

As the title should give away a minor trick to clean up your HTML output of your XLST, since when you are working with namespaces the HTML output based on a XML file will most probably look ‘crap’ containing a! lot of unnecessary info you don’t need to be outputted.

There is a very handy option for that: exclude-result-prefixes, that allows you to exclude name prefixes so that you will end up with clean HTML

   1: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" exclude-result-prefixes="xsl">


 

Eased up my life debugging html!

Share:

Albert-Jan Schot schreef

Comments (0)

Albert-Jan Schot

XSLT and currency

07

Apr

Just some simple code this time, a minor XSLT function to change values to a nice Currency Value. Like it says, it formats a number (some var names are Dutch, sorry for that):

<xsl:template name="FormatNumber">

      <xsl:param name="str" />

      <xsl:param name="defnadekomma" />

 

      <xsl:variable name="newvalueS">

            <xsl:value-of select="string($str)" />

      </xsl:variable>

 

      <xsl:variable name="newvalue">

            <xsl:choose>

                  <xsl:when test="contains($newvalueS, ',')">

                        <xsl:value-of select="substring-before($newvalueS, ',')" />

                  </xsl:when>

                  <xsl:otherwise>

                        <xsl:value-of select="$newvalueS" />

                  </xsl:otherwise>

 

            </xsl:choose>

      </xsl:variable>

 

      <xsl:variable name="nadekomma" >

            <xsl:choose>

                  <xsl:when test="contains($newvalueS, ',')">

                        <xsl:value-of select="concat(',',substring-after($newvalueS, ','))" />

                  </xsl:when>

            </xsl:choose>

      </xsl:variable>

 

      <xsl:variable name="nadekommaMax" >

            <xsl:choose>

                  <xsl:when test="string-length($nadekomma) &gt; 3">

                        <xsl:value-of select="substring($nadekomma, 1, 3)" />

                  </xsl:when>

                  <xsl:otherwise>

                        <xsl:value-of select="$defnadekomma" />

                  </xsl:otherwise>

            </xsl:choose>

      </xsl:variable>

     

      <xsl:choose>

            <xsl:when test="string-length($newvalue) &gt; 3">

                  <xsl:variable name="newvaluews">

                        <xsl:value-of select="substring($newvalue,1,string-length($newvalue) - 3)" />.<xsl:value-of select="substring($newvalue,string-length($newvalue) - 2,3)" />

                  </xsl:variable>

                  <xsl:value-of select="concat($newvaluews, $nadekommaMax)" />

            </xsl:when>

            <xsl:otherwise>

 

                  <xsl:value-of select="concat($newvalue, $nadekommaMax)" />

 

            </xsl:otherwise>

      </xsl:choose>

</xsl:template>

 

By using the following statement you get a nice Euro sign, and a price, changing the € to a $ or whatever value you want it to be, you can even change the currency.

 

<xsl:text></xsl:text>

<xsl:call-template name="FormatNumber">

      <xsl:with-param name="str" select="$prijs" />

      <xsl:with-param name="defnadekomma" select="',-'" />

</xsl:call-template>

Albert-Jan Schot schreef

Comments (0)

Albert-Jan Schot

Basic Search - Display Different Columns

31

Mar

So another minor post about search. Last post I explained the use of metadata property mappings, and their strength allowing you to show more information without a lot of changes. However I forgot to mention the fact that u can actually show them pretty easy in your existing search results.

Assuming you created your Metadata properties you can go to your search page, the XSLT of your resultswebpart to:

<?xml version="1.0" encoding="UTF-8"?>

      <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

            <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

                  <xsl:template match="/">

                        <xmp><xsl:copy-of select="*"/></xmp>

                  </xsl:template>

</xsl:stylesheet>

(More info on that on a previous post on this blog) .

Next step will be a minor change in Results Query Options, here you will have a property for Selected Columns, editing it will show you the normal columns used in your search results before the end </Columns> you can easily add a new <Column Name=”YourMetaDataProperty” />. By using the above XLST you can save the page search, and check real-time whether your column exists and contains information.

You might have to play with capitalization a bit, ‘cause sometimes the column name differs from the metadata property.

Albert-Jan Schot schreef

Comments (0)

Albert-Jan Schot
Page 1 of 1 in the XSLT category