XLST Extensions
awisto XLST extension
To simplify formatting inside XSLT documents the following XSLT extension are available. All of them allow formatting of numbers and dates based on the internationalised settings.
Integration
The Namespace of the extensions must be made known to the
<xsl:stylesheet version="2.0"
xmlns:fn="awisto:format-number"
xmlns:fd="awisto:format-date"
xmlns:fs="awisto:format-string"
xmlns:fi="awisto:format-image"
xmlns:sw="awisto:system-wide-variable"
xmlns:az="awisto:http-request"
Unused Extensions
Use only those extensions required for your data source
format-number
This extension provides functions for formatting numbers. Most numbers should already be formatted in the format of the corresponding user. If you want a different format, you can use these functions to obtain the desired formatting.
formatint (number)
Formats a integer.
- number: could be any field or the number
formatfloat(number, accuracy)
Formats a float.
- number: could be any field or the number
- accuracy: determines the accuracy, i.e. the number of decimal places
formatmoney(number, symbol, accuracy)
Formats a decimal with thespecified accuracy or the currency symbol based on the user settings. Formatmoney allows to specify the accuracy, if no accuracy is specified the default value 2 is taken
- number: could be any field or the number
- symbol: determines the currency symbol
- accuracy: determines the accuracy, i.e. the number of decimal places. Default value is 2.
<xsl:value-of select=“fn:formatfloat($myvaribale, 2)” />
formate-date
format(text, format)
Format a date text based on the user settings and the entered .NET Franwork Time- and Date-Formats.
- text: could be any field or the datetime
- format: the requested format for the date within C# Format
now() :
returns DateTime.Now. This will return the current universal time. You can use the format function if you want a specific format.
GetCalenderWeek(text)
Returns the calendar week of the given date. The calendar week is based on the i18N configuration of the datasource. The value -1
- text: could be any field or the datetime
GetDayOfYear(text)
Returns the day the year of the given date.
- text: could be any field or the datetime
GetQuarter(text)
Returns the quarter of the given date as integer between 1 and 4.
- text: could be any field or the datetime
GetQuarter(text, fiscalYearStart)
Returns the quarter of the given date as integer between 1 and 4. You can add the additional parameter fiscalYearStart to specify when your fiscal year starts. The year of the fiscal year start is ignored, only the date and month component is used for the quarter calculation.
- text: could be any field or the datetime
- fiscalYearStart: defines the start of the fiscal year of the company.
IsLeapYear(text)
Returns true if the given year is a leap year, otherwise false is returned.
- text: could be any field or the datetime
Compare(text1, text2)
Compares two given dates. Returns a value below zero if text1 is smaller then text2. Returns a value above zero if text1 is bigger then text2. Returns zero if text1 and text2 are equal.
- text1: could be any field or the datetime
- text2: could be any field or the datetime
Add(text, type, value)
With the Add function you can add a flat value to a given date. You can either add days, month, years, hours or minutes. You can specifie the type with the type field and the amount with the value field. This value is added to the given date and the result is returned.
- text: could be any field or the datetime
- type: can bei either "day" or "month" or "year" or "hour" or "minute"
- value: a number which is added to the text. The added number is within the unit specified as type.
not Unreadable
if the date is null or unreadable these date functions may return the value
format-string
This extension contains functions for editing character strings.
replace
- replace(text, search, replace)
Replace a string search in text text with the specified replace replace.
<xsl:value-of select=“fs:replace($myvaribale, ‘MyString’, ‘MyReplacement’)” />
removehtml(text)
Removes HTML elements from the given text
- text: could be any field or the text itself
IsRegExMatch(source, regExString)
This function can be used to check whether the specified string meets the RegEx condition. If the string matches the RegEx expression, true is returned. In all other cases, the answer is false.
- source: could be any field or the text itself
- regExString: The regex expression itself
<IsRegEx><xsl:value-of select="fs:IsRegExMatch(description, '\w{1}\d{1}')" /></IsRegEx>
GetRegExMatch(source, regExString, index)
The function searches a text for all matching locations according to a specified search pattern. The response of the function depends on the call in XLST.
You can obtain an XML of all RegEx hits. In this case, you must call the function using apply-templates.
<RegEx> <xsl:apply-templates select="fs:GetRegExMatch(description, '\w{1}\d{1}')" /></RegEx>
If you only want to get a specific match, you can call the function using value-of. In this case, you can specify the desired index of the RegEx match as an additional parameter.
<RegEx> <xsl:value-of select="fs:GetRegExMatch(description, '\w{1}\d{1}', '2' )" /></RegEx>
- source: could be any field or the text itself
- regExString: The regex expression itself
- index: aAn optional parameter to determine the desired RegEx match. If you do not specify anything, you will always get the first match.
ReplacePaceHolderWithXpathValues(source, xml, variableCharacter, placeHolder)
The use case for this function is a little more specific. For example, you may want to move certain text blocks so that they are not stored within the data source or template. In this case, however, you may still want to refer to values generated by the data source within the text block.
- source: could be any field or the xml vlaue
- xml: The regex expression itself
- variableCharacter:
- placeHolder:
format-image
Diese Erweiterung kann verwendet werden um Bilder zu bearbeiten. Sie können die Bilder vergrößern, verkleinern, verzerren oder schneiden.
-
Scale(image, scaleFactor)
-
image: The field which contains the image as base64 string
-
scaleFactor: The factor in percentage to scale a image up or down. A value below 100 will scale down and a value upper then 100 will scale up
-
Scale(image, width, height)
-
image: The field which contains the image as base64 string
- width: The absolut with of the image in pixel. Can be lower or bigger as the original image. If you choose a different width / height ratio the image will be warped. You can use -1 to calculate the width based on the given height to keep the current ration.
- height: The absolut height of the image in pixel. Can be lower or bigger as the original image. If you choose a different width / height ratio the image will be warped. You can use -1 to calculate the width based on the given height to keep the current ration.
Warping
Using an absolut width and height the image could be warped. You can use the absolut scaling while keeping the ratio. Just set one value to an absolut value while keeping the other value to -1
-
Cut(image, width, height, startX, startY)
-
image: The field which contains the image as base64 string
- width: The absolut with of the image in pixel. This will not scale the image. If you choose a bigger width as the original image, the image will be filled with empty space.
- height: The absolut height of the image in pixel. This will not scale the image. If you choose a bigger width as the original image, the image will be filled with empty space.
- The X position where the cut should start. The position must be within the original image.
-
The Y position where the cut should start. The position must be within the original image.
-
Crop(image)
-
image: The field which contains the image as base64 string. The function will detect the border automatically and removes it
-
Padding(image, paddingLeft, paddingTop , paddingRight, paddingBottom, color)
-
image: The field which contains the image as base64 string.
- paddingLeft: The amount of pixels which should be added as padding on the left.
- paddingTop : The amount of pixels which should be added as padding on the top.
- paddingRight: The amount of pixels which should be added as padding on the tight.
- paddingBottom: The amount of pixels which should be added as padding on the bottom.
- color: The color of the added padding. You can use either the name of the color or its HEX code
Examples for Image Scaling
- scale a image down to 25%
<xsl:value-of select="fi:Scale(documentbody, 25)"/>
- scale a image down to 50 pixel in width and 50 pixel in height
<xsl:value-of select="fi:Scale(entityimage, 50, 50)"/>
- cut an image to a widht of 300 and a height of 200, starting on the topper left corner (position 0, 0)
<xsl:value-of select="fi:Cut(documentbody, 300, 200, 0 ,0)"/>
- crop an image / remove a border
<xsl:value-of select="fi:Crop(documentbody)"/>
- add a padding of 50 pixel on each side in the red color
<xsl:value-of select="fi:Padding(documentbody, 50, 50, 50, 50, 'red')"/>
- remove the current border and add an padding of 50 pixel on each side in the red color
<xsl:value-of select="fi:Padding(fi:Crop(documentbody), 50, 50, 50, 50, 'red')"/>
system-wide-variable
-
get(variable)
- the get function of the system-wide-variable extension can be used to use a system wide variable within the xml itself. Any system wide variable can be used as parameter for the get function. The variable should be used without the @ tag.
<xsl:value-of select="sw:get('userid')"/>