-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
849 additions
and
2,370 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.DS_Store | ||
/backup |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,33 @@ | ||
# XSLT Kit | ||
|
||
This is a growing collection of XSL templates we often use for our [Symphony](http://getsymphony.com) projects. Please have a look at each template for documentation and detailed author information. We are constantly updating or adding templates. Feel free to fork the repository and contribute to this library. | ||
|
||
## Copy and Paste | ||
|
||
```xsl | ||
<xsl:import href="kit/datetime.xsl" /> | ||
<xsl:import href="kit/images.xsl" /> | ||
<xsl:import href="kit/names.xsl" /> | ||
<xsl:import href="kit/ninja.xsl" /> | ||
<xsl:import href="kit/pagination.xsl" /> | ||
<xsl:import href="kit/timedistance.xsl" /> | ||
<xsl:import href="kit/timeranges.xsl" /> | ||
<xsl:import href="kit/twitter.xsl" /> | ||
This template kit combines XSLT utilities we regularly use in our projects. Some templates require a specific XML structure provided by our [Kirby XSLT plugin](https://github.com/hananils/kirby-xslt). If you are working with Symphony CMS, have a look at the [dedicated branch](https://github.com/hananils/xslt-kit/tree/symphony). | ||
|
||
## Requirements | ||
|
||
The kit requires the EXSLT extension, <http://exslt.org/>. | ||
|
||
## Namespace | ||
|
||
All templates are namespaced, please add the following to your stylesheet: | ||
|
||
```xslt | ||
<xsl:stylesheet version="1.0" | ||
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" | ||
xmlns:kit="https://hananils.de/xslt/kit"> | ||
``` | ||
|
||
--- | ||
## Included templates and modes | ||
|
||
All templates can be applied using `<xsl:apply-templates />` using the matching mode: | ||
|
||
- `kit:transform`: If you apply this mode to a HTML structure, nothing changes in the output by default. But this mode allows you to offset the headline hierarchy, e. g. changing a `h1` to a `h3`, or to match templates to elements allowing custom transforms. This is very helpful when you are dealing with HTML sources generated using Markdown. For more information see http://www.getsymphony.com/learn/articles/view/html-ninja-technique/. | ||
- `kit:dates`: Formats Kirby XSLT date nodes to a human readable date. | ||
- `kit:dates-time`: Formats Kirby XSLT date nodes to a human readabel time. | ||
- `kit:dates-range`: Creates human readable date and time ranges from a Kirby XSLT date node. | ||
- `kit:dates-years`: Creates human readable year ranges from a node set containing year values. | ||
- `kit:list`: Converts node sets to list, e. g. using a comma separator. | ||
- `kit:links`: Creates human friendly links. | ||
- `kit:email`: Creates a HTML link from a textual e-mail node. | ||
- `kit:name`: Formats a name with title, prefix and suffix. | ||
|
||
**hana+nils · Büro für Gestaltung** | ||
Johanna und Nils Hörrmann GbR | ||
[hananils.de](http://hananils.de) · <buero@hananils.de> | ||
There is also a language template containing information about the current Kirby content language as well as translation strings. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<xsl:stylesheet version="1.0" | ||
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" | ||
xmlns:kit="https://hananils.de/xslt/kit"> | ||
|
||
<!-- | ||
* hana+nils · Büro für Gestaltung | ||
* https://hananils.de · buero@hananils.de | ||
--> | ||
|
||
<xsl:import href="dates.xsl" /> | ||
<xsl:import href="dates.time.xsl" /> | ||
|
||
<!-- | ||
* Kit: Date Ranges | ||
* | ||
* This template creates readable date and time ranges. | ||
* | ||
* # Example usage | ||
* | ||
* <xsl:apply-templates select="dates" mode="kit:dates-range" /> | ||
* | ||
* # Parameters | ||
* | ||
* - show-date | ||
* Whether to display the date or not, defaults to true | ||
* - show-time | ||
* Whether to display the time or not, defaults to true | ||
* - separator-datetime | ||
* A string used to separate date and time values, defaults to comma and space | ||
* - separator-times | ||
* A string used to separate times, defaults to a n-dash | ||
--> | ||
|
||
<xsl:template match="*" mode="kit:dates-range"> | ||
<xsl:param name="show-date" select="true()" /> | ||
<xsl:param name="show-time" select="true()" /> | ||
<xsl:param name="separator-datetime" select="', '" /> | ||
<xsl:param name="separator-times" select="'–'" /> | ||
|
||
<!-- Timerange --> | ||
<xsl:choose> | ||
|
||
<!-- Same day --> | ||
<xsl:when test="start = end or not(end)"> | ||
<xsl:if test="$show-date = true()"> | ||
<xsl:apply-templates match="start" mode="kit:dates"> | ||
<xsl:with-param name="format" select="'long'" /> | ||
</xsl:apply-templates> | ||
</xsl:if> | ||
|
||
<xsl:if test="$show-date = true() and $show-time = true()"> | ||
<xsl:value-of select="$separator-datetime" /> | ||
</xsl:if> | ||
|
||
<xsl:if test="$show-time = true()"> | ||
<xsl:apply-templates select="start" mode="kit:dates-time" /> | ||
|
||
<xsl:if test="start/@time and end/time"> | ||
<xsl:value-of select="$separator-times" /> | ||
</xsl:if> | ||
|
||
<xsl:apply-templates select="end" mode="kit:dates-time" /> | ||
</xsl:if> | ||
</xsl:when> | ||
|
||
<!-- Different day --> | ||
<xsl:otherwise> | ||
<xsl:if test="$show-date = true()"> | ||
<xsl:apply-templates match="start" mode="kit:dates"> | ||
<xsl:with-param name="format" select="'long'" /> | ||
</xsl:apply-templates> | ||
</xsl:if> | ||
|
||
<xsl:if test="$show-date = true() and $show-time = true()"> | ||
<xsl:value-of select="$separator-datetime" /> | ||
</xsl:if> | ||
|
||
<xsl:if test="$show-time = true()"> | ||
<xsl:apply-templates select="start" mode="kit:dates-time" /> | ||
</xsl:if> | ||
|
||
<xsl:value-of select="concat(' ', $separator-times, ' ')" /> | ||
|
||
<xsl:if test="$show-date = true()"> | ||
<xsl:apply-templates match="end" mode="kit:dates"> | ||
<xsl:with-param name="format" select="'long'" /> | ||
</xsl:apply-templates> | ||
</xsl:if> | ||
|
||
<xsl:if test="$show-date = true() and $show-time = true()"> | ||
<xsl:value-of select="$separator-datetime" /> | ||
</xsl:if> | ||
|
||
<xsl:if test="$show-time = true()"> | ||
<xsl:apply-templates select="end" mode="kit:dates-time" /> | ||
</xsl:if> | ||
</xsl:otherwise> | ||
</xsl:choose> | ||
</xsl:template> | ||
|
||
|
||
</xsl:stylesheet> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<xsl:stylesheet version="1.0" | ||
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" | ||
xmlns:kit="https://hananils.de/xslt/kit"> | ||
|
||
<!-- | ||
* hana+nils · Büro für Gestaltung | ||
* https://hananils.de · buero@hananils.de | ||
--> | ||
|
||
<xsl:include href="languages.xsl" /> | ||
|
||
<!-- | ||
* Kit: Time | ||
* | ||
* This template formats times. | ||
* | ||
* # Example usage | ||
* | ||
* <xsl:apply-templates select="time" select="kit:dates-time" /> | ||
* | ||
* # Parameters | ||
* | ||
* - zero | ||
* Whether to include a leading zero or not, defaults to false | ||
* - ampm | ||
* Whether to use am/pm times or not, defaults to false, | ||
* only applies to English times | ||
--> | ||
|
||
<xsl:template match="*" mode="kit:dates-time"> | ||
<xsl:param name="zero" select="false()" /> | ||
<xsl:param name="ampm" select="false()" /> | ||
|
||
<xsl:variable name="number-format"> | ||
<xsl:choose> | ||
<xsl:when test="$zero = true()">00</xsl:when> | ||
<xsl:otherwise>#0</xsl:otherwise> | ||
</xsl:choose> | ||
</xsl:variable> | ||
|
||
<xsl:variable name="hours" select="format-number(substring-before(':', @time), $number-format)" /> | ||
<xsl:variable name="minutes" select="substring-after(':', @time)" /> | ||
|
||
<xsl:choose> | ||
<xsl:when test="$kit:language-code = 'de'"> | ||
<xsl:apply-templates select="." mode="kit:time-formatter-german"> | ||
<xsl:with-param name="hours" select="$hours" /> | ||
<xsl:with-param name="minutes" select="$minutes" /> | ||
</xsl:apply-templates> | ||
</xsl:when> | ||
<xsl:otherwise> | ||
<xsl:apply-templates select="." mode="kit:time-formatter-english"> | ||
<xsl:with-param name="hours" select="$hours" /> | ||
<xsl:with-param name="minutes" select="$minutes" /> | ||
<xsl:with-param name="twentyfour" select="$ampm" /> | ||
</xsl:apply-templates> | ||
</xsl:otherwise> | ||
</xsl:choose> | ||
</xsl:template> | ||
|
||
<!-- | ||
German | ||
--> | ||
|
||
<xsl:template select="*" mode="kit:time-formatter-german"> | ||
<xsl:param name="hours" /> | ||
<xsl:param name="minutes" /> | ||
|
||
<xsl:value-of select="concat($hours, ':', $minutes, ' Uhr')" /> | ||
</xsl:template> | ||
|
||
<!-- | ||
English | ||
--> | ||
|
||
<xsl:template select="*" mode="kit:time-formatter-english"> | ||
<xsl:param name="ampm" select="false()" /> | ||
<xsl:param name="hours" /> | ||
<xsl:param name="minutes" /> | ||
|
||
<xsl:choose> | ||
<xsl:when test="$ampm = true() and $hours < 12"> | ||
<xsl:value-of select="concat($hours, ':', $minutes, 'am')" /> | ||
</xsl:when> | ||
<xsl:when test="$ampm = true() and $hours > 12"> | ||
<xsl:value-of select="concat($hours - 12, ':', $minutes, 'pm')" /> | ||
</xsl:when> | ||
<xsl:otherwise> | ||
<xsl:value-of select="concat($hours, ':', $minutes)" /> | ||
</xsl:otherwise> | ||
</xsl:choose> | ||
</xsl:template> | ||
|
||
|
||
</xsl:stylesheet> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<xsl:stylesheet version="1.0" | ||
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" | ||
xmlns:kit="https://hananils.de/xslt/kit"> | ||
|
||
<!-- | ||
* hana+nils · Büro für Gestaltung | ||
* https://hananils.de · buero@hananils.de | ||
--> | ||
|
||
<xsl:include href="languages.xsl" /> | ||
|
||
<!-- | ||
* Kit: Dates | ||
* | ||
* This template formats dates to one of the following formats: | ||
* | ||
* - long | ||
* The full date with day, long month and long year | ||
* - short | ||
* The full date with day, shortened month and long year | ||
* - numeric | ||
* The full date in localized tabular format | ||
* | ||
* # Example usage | ||
* | ||
* <xsl:apply-templates select="date" mode="kit:dates" /> | ||
* | ||
* # Parameters | ||
* | ||
* - format | ||
* The output format, either long, short or numeric, defaults to numeric | ||
* - zero | ||
* Whether to include a leading zero or not, defaults to false | ||
* | ||
* # Requirements | ||
* | ||
* The template requires the `datetime` and date type nodes from Kirby XSLT, | ||
* https://github.com/hananils/kirby-xslt | ||
--> | ||
|
||
<xsl:template match="*" mode="kit:dates"> | ||
<xsl:param name="format" select="numeric" /> | ||
<xsl:param name="zero" select="false()" /> | ||
|
||
<xsl:variable name="month" select="/data/datetime/language[@id = $kit:language-code]/months/month[@id = current()/@month]" /> | ||
<xsl:variable name="number-format"> | ||
<xsl:choose> | ||
<xsl:when test="$zero = true()">00</xsl:when> | ||
<xsl:otherwise>#0</xsl:otherwise> | ||
</xsl:choose> | ||
</xsl:variable> | ||
|
||
<xsl:choose> | ||
<xsl:when test="$kit:language-code = 'de'"> | ||
<xsl:apply-templates select="." mode="kit:dates-formatter-german"> | ||
<xsl:with-param name="format" select="$format" /> | ||
<xsl:with-param name="month" select="$month" /> | ||
<xsl:with-param name="number-format" select="$number-format" /> | ||
</xsl:apply-templates> | ||
</xsl:when> | ||
<xsl:otherwise> | ||
<xsl:apply-templates select="." mode="kit:dates-formatter-english"> | ||
<xsl:with-param name="format" select="$format" /> | ||
<xsl:with-param name="month" select="$month" /> | ||
<xsl:with-param name="number-format" select="$number-format" /> | ||
</xsl:apply-templates> | ||
</xsl:otherwise> | ||
</xsl:choose> | ||
</xsl:template> | ||
|
||
<!-- | ||
German | ||
--> | ||
<xsl:template match="*" mode="kit:dates-formatter-german"> | ||
<xsl:param name="format" select="numeric" /> | ||
<xsl:param name="month" /> | ||
<xsl:param name="number-format" /> | ||
|
||
<xsl:choose> | ||
<xsl:when test="$format = 'long' and $month != ''"> | ||
<xsl:value-of select="concat(format-number(@day, $number-format), '. ', $month, ' ', @year)" /> | ||
</xsl:when> | ||
<xsl:when test="$format = 'short' and $month != ''"> | ||
<xsl:value-of select="concat(format-number(@day, $number-format), '. ', $month/@abbr, '. ', @year)" /> | ||
</xsl:when> | ||
<xsl:otherwise> | ||
<xsl:value-of select="concat(format-number(@day, $number-format), '.', format-number(@month, $number-format), '.', @year)" /> | ||
</xsl:otherwise> | ||
</xsl:choose> | ||
</xsl:template> | ||
|
||
<!-- | ||
English | ||
--> | ||
<xsl:template match="*" mode="kit:dates-formatter-english"> | ||
<xsl:param name="format" select="numeric" /> | ||
<xsl:param name="month" /> | ||
<xsl:param name="number-format" /> | ||
|
||
<xsl:choose> | ||
<xsl:when test="$format = 'long' and $month != ''"> | ||
<xsl:value-of select="concat($month, ' ', format-number(@day, $number-format), ', ', @year)" /> | ||
</xsl:when> | ||
<xsl:when test="$format = 'short' and $month != ''"> | ||
<xsl:value-of select="concat($month/@abbr, '. ', format-number(@day, $number-format), ', ', @year)" /> | ||
</xsl:when> | ||
<xsl:otherwise> | ||
<xsl:value-of select="concat(format-number(@day, $number-format), '/', format-number(@month, $number-format), '/', @year)" /> | ||
</xsl:otherwise> | ||
</xsl:choose> | ||
</xsl:template> | ||
|
||
|
||
</xsl:stylesheet> |
Oops, something went wrong.