Parameterized Macro: I want to display True/False field as "Yes" or "No"
Hi,
XSLT newbie here. I can't seem to figure this one out. I want to pass the field alias of a document's True/False field to a macro, and have it display the value as Yes or No. Here is what I have:
EDIT: Updated to fit your initial setup with a macro parameter stating the name of the property to test. You just need to get rid of the apostrophes in your code to make it work.)
Parameterized Macro: I want to display True/False field as "Yes" or "No"
Hi,
XSLT newbie here. I can't seem to figure this one out. I want to pass the field alias of a document's True/False field to a macro, and have it display the value as Yes or No. Here is what I have:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp " "> ]>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxml="urn:schemas-microsoft-com:xslt"
xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets"
exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">
<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:param name="currentPage"/>
<xsl:variable name="field" select="/macro/field"/>
<xsl:template match="/">
<!-- start writing XSLT -->
<xsl:if test="data[@alias= '$field']=1">
Yes
</xsl:if>
<xsl:if test="data[@alias= '$field']=0">
No
</xsl:if>
</xsl:template>
</xsl:stylesheet>
Hi Nathan,
Sorry, just about to leave work, so don't have time to actually verify this syntax, but hopefully it gives you the idea to start searching around...
Typically, I would pass the value of the field to the xslt as a parameter rather than the field name - something like:
then something like
...
<xsl:template match="/">
<!-- start writing XSLT -->
<xsl:if test="$field='1'">
Yes
</xsl:if>
...
If you want to do it the way your're doing, its something like (although depends on if you're using 4 or 4.5:
...
<xsl:template match="/">
<!-- start writing XSLT -->
<xsl:if test="string($currentPage/data[@alias= '$field'])='1'">
Yes
</xsl:if>
...
Thanks a bunch!!!
Hi Nathan (+ Patrick)
Here's a one-liner that does the trick:
/Chriztian
EDIT: Updated to fit your initial setup with a macro parameter stating the name of the property to test. You just need to get rid of the apostrophes in your code to make it work.)
is working on a reply...