Created
February 28, 2013 16:34
-
-
Save uniquelau/5058019 to your computer and use it in GitHub Desktop.
XSLT Document Property templating with Fallback.
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
<?xml version="1.0" encoding="utf-8"?> | |
<xsl:stylesheet | |
version="1.0" | |
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" | |
xmlns:umb="urn:umbraco.library" | |
exclude-result-prefixes="umb" | |
> | |
<xsl:output method="xml" indent="yes" omit-xml-declaration="yes" /> | |
<!-- Default Article Template, used for all nodes. --> | |
<xsl:template match="*" mode="article"> | |
<h1> | |
<xsl:value-of select="contentHeader | @nodeName[not(./contentHeader)] [1]" /> | |
</h1> | |
<xsl:apply-templates select="contentBody" mode="WYSIWYG" /> | |
<!-- why not template the header, so it can be overidden/used on say a comment, etc--> | |
<h2> | |
<xsl:apply-templates select="contentHeader | @nodeName[not(./contentHeader)] [1]" mode="test" /> | |
</h2> | |
</xsl:template> | |
<xsl:template match="*" mode="test"> | |
<b>big</b> | |
<i> | |
<xsl:value-of select="."/> | |
<!-- outputs null --> | |
</i> | |
<xsl:copy-of select="."/> | |
<!-- outputs <contentHeader></contentHeader> --> | |
</xsl:template> | |
</xsl:stylesheet> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Line 14 (and 20) doesn't do what you think they do (I think :-)
They will probably always give you
@nodeName
- and it's a little tricky to explain why (which I'll happily do over beer someday)Here's what I do:
(The second one works for the first scenario too, so I always use the second)
When using apply-templates, you need to make the template match both elements and attributes in "test" mode (e.g.:
match="* | @*"
)