Created
April 23, 2011 20:39
-
-
Save greystate/938957 to your computer and use it in GitHub Desktop.
Code listings for "Using Dictionary Items in XSLT" (Pimp My XSLT article)
This file contains hidden or 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
| <xsl:template match="/"> | |
| <h2><xsl:value-of select="umbraco.library:GetDictionaryItem('SearchTitle')" /></h2> | |
| <!-- do stuff --> | |
| </xsl:template> |
This file contains hidden or 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
| <xsl:template match="/"> | |
| <h2><xsl:value-of select="umbraco.library:GetDictionaryItem('SearchTitle')" /></h2> | |
| <form> | |
| <p> | |
| <input type="search" placeholder="{umbraco.library:GetDictionaryItem('SearchFieldPlaceholder')}" name="q" /> | |
| <button type="submit"> | |
| <xsl:value-of select="umbraco.library:GetDictionaryItem('SearchButtonText')" /> | |
| </button> | |
| </p> | |
| </form> | |
| </xsl:template> |
This file contains hidden or 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
| <DictionaryItems> | |
| <DictionaryItem key="SearchTitle">Are you lost?</DictionaryItem> | |
| <DictionaryItem key="SearchButtonText">Find</DictionaryItem> | |
| <DictionaryItem key="SearchFieldPlaceholder">Type some keywords here...</DictionaryItem> | |
| </DictionaryItems> |
This file contains hidden or 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
| <xsl:variable name="search-labels" select="umbraco.library:GetDictionaryItems('SearchLabels')" /> |
This file contains hidden or 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
| <!-- Before: --> | |
| <h2><xsl:value-of select="umbraco.library:GetDictionaryItem('SearchTitle')" /></h2> | |
| <!-- After: --> | |
| <h2><xsl:value-of select="$search-labels/DictionaryItems/DictionaryItem[@key = 'SearchTitle']" /></h2> |
This file contains hidden or 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
| <!-- Grab each section of labels --> | |
| <xsl:variable name="frontpage-labels" select="umbraco.library:GetDictionaryItems('FrontPage')/DictionaryItems/DictionaryItem" /> | |
| <xsl:variable name="search-labels" select="umbraco.library:GetDictionaryItems('Search')/DictionaryItems/DictionaryItem" /> | |
| <xsl:variable name="product-labels" select="umbraco.library:GetDictionaryItems('Products')/DictionaryItems/DictionaryItem" /> | |
| <!-- Join them all for easy access --> | |
| <xsl:variable name="labels" select="$frontpage-labels | $search-labels | $product-labels" /> |
This file contains hidden or 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
| <xsl:template match="/"> | |
| <h2><xsl:value-of select="$labels[@key = 'SearchTitle']" /></h2> | |
| <form> | |
| <p> | |
| <input type="search" placeholder="{$labels[@key = 'SearchFieldPlaceholder']}" name="q" /> | |
| <button type="submit"> | |
| <xsl:value-of select="$labels[@key = 'SearchButtonText']" /> | |
| </button> | |
| </p> | |
| </form> | |
| </xsl:template> |
This file contains hidden or 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
| <!-- | |
| Take the label key from the element's name; | |
| If no DictionaryItem defined for this, wrap the element's name in hash-signs, | |
| to signal a missing translation to the frontend. | |
| --> | |
| <xsl:template match="* | @*" mode="label"> | |
| <xsl:value-of select="$labels[@key = name(current())]" /> | |
| <xsl:if test="not($labels[@key = name(current())])"> | |
| <xsl:value-of select="concat('#', name(), '#')" /> | |
| </xsl:if> | |
| </xsl:template> |
This file contains hidden or 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
| <xsl:template match="NewsItem"> | |
| <xsl:apply-templates select="newsDate" /> | |
| <!-- do stuff --> | |
| </xsl:template> | |
| <xsl:template match="newsDate"> | |
| <h3> | |
| <!-- Write localized 'Date' label --> | |
| <xsl:apply-templates select="." mode="label" /> | |
| <xsl:value-of select="concat(': ', .)" /> | |
| </h3> | |
| </xsl:template> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment