I am doing a Umbraco site (my first) and I am having a serious issue with loading an image on one of my pages.
I created a new template and one section of the code I inserted the following:
<a href="{umbraco.library:NiceUrl($currentPage/../#id)}">"
<xsl:value-of select="$currentPage/../#nodeName" />
</a>
When I look at the results in the browser it displays the results exactly the same, it does not get executed before rendering. ie I see this when I look at the "view source" in the browser:
<a href="{umbraco.library:NiceUrl($currentPage/../#id)}">
<xsl:value-of select="$currentPage/../#nodeName" />
</a>
The confusing part is that when I run the following :
<img src='<umbraco:Item field="articlePhoto" runat="server"></umbraco:Item>' />
It actually generates this tag :
<img src="~/media/554/bath.png">
The main thing I am trying to do is load a dynamic field/url into an image tag.
Any help would be greatly appreciated.
Thanks
I'm assuming you actually have two problems here and that they're not linked.
First Problem: Code not executing
You are trying to execute XSLT code directly inside the template. The template only accepts what you would normally find in a ASPX page (e.g. HTML, Server Controls, Registered Umbraco Controls etc) and will not parse any XSLT constructs but output them directly into the source, as exemplified in your question.
You will need to create an XSLT file in the developer section, along with it's associated macro, which is usually created automatically along with the XSLT. Then you simply import the macro into the template.
Template Snippet:
<umbraco:Macro Alias="MyMacro" runat="server" />
XSLT Snippet:
<a href="{umbraco.library:NiceUrl($currentPage/../#id)}">
<xsl:value-of select="$currentPage/../#nodeName" />
</a>
Second Problem: Image not showing
It's weird Umbraco is preprending the ~ symbol as your code is indeed correct (it's working on my Umbraco - Version 4.7.1). As a work-around, try creating an XSLT file and using the following XSLT code. At least with XSLT you're able to put in coding logic, which will be needed as your pages become more complex.
XSLT Snippet:
<xsl:if test="$currentPage/articlePhoto != ''">
<img src="{$currentPage/articlePhoto}" />
</xsl:if>
Hope that helps.
Related
I'm using Scapy to scrape some data from a site and I need help using Xpath to select "data" from the following.
<span class="result_item"><span class="text3"><span class="header_text3">**data**</span><br />
**data**<br />
**data**</span> <span class="phone_button_out"><span class="phone_button" style="margin-top: 0"
onclick="pageTracker._trackEvent('USDSearch','Call Now!F');phone_win.open('name','**data**',27101650,0)">
Call Now!<br />
</span></span>
What statements can I use to select the necessary data? I hope this isn't a stupid question. If it is, please point me in the right direction.
There are multiple data elements to get in the posted html. Assuming that <span class="result_item"> is parent of the items, you can try the following:
To get header:
//span[#class='result_item']/span[#class='header_text3']/text()
To get anchor link data:
//span[#class='result_item']/a/text()
Also, to help with xpaths, install Firebug Addon in Firefox, then FirePath addon on Firebug. Pointing to elements will give you autogenerated xpaths (good for beginners. sometime needs xpath tuning)
The Ajax accordion on my page isn't functioning at all. It displays fine on the page, but I can't seem to expand/collapse the panes when I click on their Headers.
Here's my code (just the HTML portion as I'm not aware of any code behind that is needed):
<aj:Accordion runat="server" ID="acMain" SelectedIndex="0"
FadeTransitions="true"
TransitionDuration="400"
FramesPerSecond="40" RequireOpenedPane="false" TabIndex="0"
SuppressHeaderPostbacks="true" HeaderCssClass="acHeader"
HeaderSelectedCssClass="acHeaderSelected">
<Panes>
<aj:AccordionPane runat="server" ID="Panel1">
<Header>
...
</Header>
<Content>
...
</Content>
</aj:AccordionPane>
<aj:AccordionPane runat="server" ID="Panel2">
<Header>
...
</Header>
<Content>
...
</Content>
</aj:AccordionPane>
</Panes>
</aj:Accordion>
I've checked the official page for the Accordion as well as a number of blogs on the subject (all of which seem to be a copy of the official page with the author's own wording) and according to all of this, I can't see that I've done anything wrong or missed anything out.
Matter of fact, I've checked an Accordion my boss made a while back and my code's basically the same as his (only panel content is different) and he has no code-behind either, so I'm really lost here.
Any help will be greatly appreciated
EDIT
After adapting my code according to a sample on asp.net, I've managed to collapse the first pane (SelectedIndex 0), but the other one won't expand :/
So I copied the accordion code from the asp.net how to page and put my content into the panes, still had no effect.
As it turns out, there was a rogue </div> tag in my content that was wrecking the accordion so I recommend that anyone having any similar problems checks their content very thoroughly.
Also, it's worth noting here that as this particular sample worked for me and because I'm telling you to use it if you're having trouble, it's author did leave an incorrectly closed </p> tag that might cause problems with your accordion during testing, so watch out for that.
I have the following code
<xsl:template name="toggle">
<xsl:param name="target"/>
<xsl:param name="show"/>
<input type="image" src="glass.png" />
<xsl:attribute name="onclick">
toggle('<xsl:value-of select="$target"/>','<xsl:value-of select="$show"/>');
</xsl:attribute>
</input>
</xsl:template>
I want to add an external image which is not part of xml file. I want to replace my Submit button with an image.
When using the above code I am unable to get the image as output.
Any ideas on how to do it?
Do you know what HTML you want to generate?
If you do, then tell us.
If you don't, then you have an HTML problem, not an XSLT problem.
Never try to write code in XSLT until you know what output HTML you want it to produce. Actually, I think it was Dijkstra who said you should never start writing any program until you know what output you want it to produce. A good principle. When applied to XSLT, remember that the output in this sense is an HTML document, not a screen displayed by the browser.
I have a Plone 3.5 site and I am trying to embedded Simple Social's FB Like action for a content in a collective.xdv theme. The FB Like function is embedded in an XML tag
<fb:like></fb:like>
I am trying to select its XPATH via
//*[local-name()="like"]
However, I do not see any output. Is the above supported in collective.xdv? Is there another way to select the fb:like tag in XPATH?
The libxml2 HTMLParser used by lxml and thus xdv/diazo strips namespace prefixes, so you should be able to select it with "//like".
You will need to add some xslt code to fix up those tags, as they must be rendered as in order to work:
<xsl:template match="activity|add-profile-tab|bookmark|comments|friendpile|like|like-box|live-stream|login-button|pronoun|recommendations|serverFbml|profile-pic|user-status">
<xsl:element name="fb:{local-name()}" xmlns:fb="http://www.facebook.com/2008/fbml">
<xsl:apply-templates select="#*|node()"/>
</xsl:element>
</xsl:template>
While xdv/diazo could be made to work with the XMLParser you would then need to ensure that you added an xmlns:fb="..." declaration to your document and that all your input was valid xhtml, which is difficult to ensure with browser based html editors.
Laurence
aiui, that's not how local-name works. You need to match on a namespace-qualified tag, and then local-name() returns the unqualified name. I believe //* is only returning a nodeset of tags in the default namespace.
Have you tried //fb:like? [I know, that's far too easy - and I think it's wrong - but then again, it is easy :-) ]
I have played for a while writing XPath but am unable to come up with exactly what I want.
I'm trying to write XPath for link(click1 and click2 in code snippet below) based on known text(myidentity in code snippet below). Can someone take a look into and suggest possible solution?
HTML code snippet:
<div class="abc">
<a onclick="mycontroller.goto('xx','yy'); return false;" href="#">
<img src="images/controls/inheritance.gif"/>
</a>
myidentity
<span>
<a onclick="mycontroller.goto('xx','yy'); return false;" href="#">click1</a>
<a onclick="mycontroller.goto('xx','yy'); return false;" href="#">click2</a>
</span>
</div>
You don't need to use XPath here, you could use a CSS locator. These are often faster and more compatible across different browsers.
css=div:contains(myidentity) > span a:nth-child(1) //click1
css=div:contains(myidentity) > span a:nth-child(2) //click2
Note that the > is only required to workaround a bug in the CSS locator library used by Selenium.
Hard to say without seeing the rest of the HTML but the following should work:
//div[text()[contains(., "myidentity")]]/span/a
See Macro's answer - this form should be used.
//div[text()[contains(., "myidentity")]]/span/a[2]
The following only works with one section of text in the containing div.
You'll need to select based on the text containing your identity text.
Xpath for click1
//div[contains(text(),"myidentity")]/span/a[1]
Xpath for click2
//div[contains(text(),"myidentity")]/span/a[2]