Our Forum has Moved

This site is our old forum and is only here for achive until we get proper 301 redirects setup to make Google happy.

Please use our new community site - Our Umbraco - which contains an improved forum, documentation wiki, package repository and a member locator.

Go to Our Umbraco now

Learn everything about Umbraco
if statement not working. Options
norphf
Posted: Wednesday, June 03, 2009 11:22:29 PM
Rank: Enthusiast

Joined: 7/21/2007
Posts: 26
Location: Ringe, Denmark
Hi

I have this:
Code:

Template:
<umbraco:Macro imgAlias="imgPic" Alias="Test" runat="server"></umbraco:Macro>

*** The Property alias of the Media Picker is (of cause) imgPic ***

XSLT:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
<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"
    exclude-result-prefixes="msxml umbraco.library">


<xsl:output method="xml" omit-xml-declaration="yes"/>

<xsl:param name="currentPage"/>
<xsl:variable name="imgAlias"  select="/macro/imgAlias"/>
<xsl:template match="/">

<xsl:if test="$imgAlias != ''">
<a>
    <xsl:attribute name="href">
        <xsl:value-of select="umbraco.library:GetMedia($currentPage/data [@alias=$imgAlias], 'false')/data [@alias='umbracoFile']" />
    </xsl:attribute>
<img>
    <xsl:attribute name="src">
        <xsl:text>/umbraco/ImageGen.ashx?image=</xsl:text>
        <xsl:value-of select="umbraco.library:GetMedia($currentPage/data [@alias=$imgAlias], 'false')/data [@alias='umbracoFile']" />
        <xsl:text>&amp;width=100</xsl:text>
        <xsl:text>&amp;height=100</xsl:text>
        <xsl:text>&amp;constrain=true</xsl:text>
    </xsl:attribute>
</img>
</a>
</xsl:if>
</xsl:template>

</xsl:stylesheet>

Running on umbraco v 4.0.0 (Assembly version: 1.0.3219.29118) Beta and is working fine.

I the copied the xslt to a new site's xslt file, created the tab/property needed and nothing happens.

I have tried to write some ordenary text i the if statement at it is not written on the page, but something written in the xslt outside the if statement is written on the page.

I also tried to change "<xsl:if test="$imgAlias != ''">" with "<xsl:if test="$imgAlias = ''">
As if it was not different from '' it must equals '' but it does not get into the if anyway.

Does anyone have any clue on what's going on?

The new site is running umbraco v 4.0.1 (Assembly version: 1.0.3373.718)

/Lars Mortensen
tommyp
Posted: Thursday, June 04, 2009 12:06:57 AM
Rank: Fanatic

Joined: 10/14/2007
Posts: 214
Location: Allerød, Denmark
Hi Lars,
it sounds as if something is wrong with your imgAlias parameter. Did you spell it correctly and also add a value in your macro-call? You could try displaying the $imgAlias content outside the if.

>Tommy


blackpoint.dk - Umbraco workbench - for people suffering from xslt amnesia.
hoehler
Posted: Thursday, June 04, 2009 9:34:52 AM

Rank: Addict

Joined: 7/19/2006
Posts: 634
Location: Bad Homburg, Germany
try

Code:
<xsl:if test="not(string($imgAlias))">


This works for me

Thomas

• 2007/2008 MVP • www.thoehler.comblog.thoehler.com • Bad Homburg, Germany
norphf
Posted: Saturday, June 06, 2009 12:16:22 AM
Rank: Enthusiast

Joined: 7/21/2007
Posts: 26
Location: Ringe, Denmark
Hi

Tommy, I have copy/pasted so I hope not it is spell error. I have pasted the macro call at the top of the code section, and the macro itself underneath so you can see if I call it write.
I have tried to write the variable outside the if with this code
Code:
<div>
<xsl:attribute name="text">
<xsl:text>Start</xsl:text>
<xsl:value-of select="$imgAlias" />
<xsl:text>Slut</xsl:text>
</xsl:attribute>
</div>


I get this in the page sourcecode: "div text="StartSlut" />" so it does not output anything.
(If I have done it right, its probably not the best way.)

hoehler, if I try to use your code I get this error:
Code:
(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime, XPathNavigator {urn:schemas-microsoft-com:xslt-debug}current)
at Root(XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime)
at System.Xml.Xsl.XmlILCommand.Execute(Object defaultDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlWriter writer, Boolean closeWriter)
at System.Xml.Xsl.XmlILCommand.Execute(IXPathNavigable contextDocument, XmlResolver dataSources, XsltArgumentList argumentList, XmlWriter results)
at System.Xml.Xsl.XslCompiledTransform.Transform(IXPathNavigable input, XsltArgumentList arguments, TextWriter results)
at umbraco.presentation.webservices.codeEditorSave.SaveXslt(String fileName, String oldName, String fileContents, Boolean ignoreDebugging)


I have just upgraded to version "umbraco v 4.0.2.1 (Assembly version: 1.0.3441.17657)"

Any other thoughts?

/Lars
tommyp
Posted: Monday, June 08, 2009 8:44:22 AM
Rank: Fanatic

Joined: 10/14/2007
Posts: 214
Location: Allerød, Denmark
Lars, are you sure you created the imgAlias parameter correctly on the macro parameters tab - and are you sure you are passing a value when using the parameter?

>Tommy


blackpoint.dk - Umbraco workbench - for people suffering from xslt amnesia.
norphf
Posted: Monday, June 08, 2009 9:56:52 AM
Rank: Enthusiast

Joined: 7/21/2007
Posts: 26
Location: Ringe, Denmark
Ahhhhhh sorry, no I had forgot there was a parameter tab on the Marco, and did not get it the first time you tried.
Now the response thing I made responses what it's supposed to.

It still, however does not work, but will look into that and response back.

Thank you for your help so far.
warren
Posted: Monday, June 08, 2009 11:01:47 AM

Rank: Umbracoholic

Joined: 7/19/2006
Posts: 1,025
Location: Benfleet, Essex, UK
OK norphf I recommend to help you debug before your if is to either do

Code:
<xsl:value-of select="$imgAlias" />

or
Code:
<xsl:copy-of select="$imgAlias" />


Warren :)

Warren Buckley an Umbraco MVP 08-09 & level 1 certified developer

Are you NEW to Umbraco? Download CWS to help you learn Umbraco quickly
NOW Available from the Official Umbraco Package Repository
norphf
Posted: Sunday, June 14, 2009 4:56:27 PM
Rank: Enthusiast

Joined: 7/21/2007
Posts: 26
Location: Ringe, Denmark
Sorry for the long reply, its working now thank you all.

The forum has moved

This forum is no longer in use, so you can't reply to this message - please go to Our Umbraco

Users browsing this topic
Guest


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.