How do I access the querystring in an Umbraco template? - templates

I'm trying to get hold of the querystring directly from the template in Umbraco, but can't seem to figure it out..
For example:
/mypage.aspx?p=bek
I can do it with <%=HttpContext.Current.Request["p"]%>, but I want it in a field...
Something like this:
Any ideas?

Ok, so I fixed it.
Found this:
http://forum.umbraco.org/yaf_postst6663_Get-querystring-in-template.aspx
If anyone else is interested, you do the following..
Create a xslt file with the name "QueryStringExtractor" and paste the below code where it belongs.
<xsl:param name="currentPage"/>
<xsl:variable name="yourvalue" select="//macro/myparam" />
<xsl:template match="/">
<!-- start writing XSLT -->
<xsl:value-of select="$yourvalue" />
</xsl:template>
Save and update the Umbraco page and you'll see a macro under "Macros" with the same namne.
In the macro you add the parameter "myparam" (I put it as text). Save!
Then in your template just past the following code and you're good to go!
<ul>
<umbraco:Macro Alias="QueryStringExtractor" myparam="[#p]" runat="server"></umbraco:Macro>
</ul>
So now when you enter the querystring "?p=something" you'll get "something" written on the page.
Notice that you can pass any "p" to the macro.
Hope this helps someone else!

Related

Referencing custom elements in DocBook

another weekend and time to further play around with DocBook :-)
I added custom elements to my DocBook document and am translating them to FO and then to PDF via a XSLT transformation. This all works pretty fine. For example, I'm having a custom chapter element like:
<MyChapter xml:id="mychapter">
<title>Test</title>
</MyChapter
The background is that I want to enforce certain structures in that document and that basically works very well. There is only one thing that does not work and that I'm stuck with. My custom elements cannot be the target of an xref. E.g. the following does not work:
<xref linkend="mychapter"/>
While I think that I understand the reason that it is not working, I'm completely lost in fixing this. Did anybody here do anything similiar before and could give me a hint on how to approach this?
EDIT:
Following the first answer, I looked into what happens if (standard) sect3 is referenced. This seems to be controlled by the following template in this file:
<xsl:template match="d:section|d:simplesect
|d:sect1|d:sect2|d:sect3|d:sect4|d:sect5
|d:refsect1|d:refsect2|d:refsect3|d:refsection" mode="xref-to">
<xsl:param name="referrer"/>
<xsl:param name="xrefstyle"/>
<xsl:param name="verbose" select="1"/>
<xsl:apply-templates select="." mode="object.xref.markup">
<xsl:with-param name="purpose" select="'xref'"/>
<xsl:with-param name="xrefstyle" select="$xrefstyle"/>
<xsl:with-param name="referrer" select="$referrer"/>
<xsl:with-param name="verbose" select="$verbose"/>
</xsl:apply-templates>
<!-- FIXME: What about "in Chapter X"? -->
</xsl:template>
I'm trying to follow the logic here but I get stucked at
<xsl:apply-templates select="." mode="object.xref.markup">
What does this line do?
Usually DocBook xref referencing logic is quite straightforward. If someone try to illustrate this logic by using human words it would be something like: put the link to the object1 with xml:id1 (using linkend) and get generated text from object2 with xml:id2 (using endterm) as link text.
So, I suggest you want to put the mychapter title as a reference text. I would be change your sample as follows:
<MyChapter xml:id="mychapter">
<title xml:id="mychapter_title">Test</title>
</MyChapter>
Link snippet:
<xref linkend="mychapter" endterm="mychapter_title"/>
You'll get the reference (link itself) to your chapter with a reference text (link text) from a chapter title.
This schema certainly works with default elements and should work with your custom elements if you use the default xsl template adopted to your custom mychapter.
This logic is described very well here: http://www.sagehill.net/docbookxsl/CrossRefs.html

XSL Substring-before with HTML characters

I am pulling in an rss feed which contains a joke followed by a number of links to share the joke on different services. As shown below:
It may be worth noting that when I tried to copy and paste the text from this output, the links did not copy into notepad, and pasted as pictures into MS Word.
In my XSL I am using substring-before in an attempt to exclude these links from my output, but the only consistent character I can think to use is the <a href from the hyperlinks, which will always be at the end. Is this possible? My first pass at it failed, is there an escape character I should include?
Perhaps I will just try to exclude the last X characters to remove the links
Unfortunately I could not find an XML version of the feed either, my source is here: http://feeds.feedburner.com/DailyJokes-ACleanJokeEveryday?format=xml
Here is the XSL I am working with, which is currently hard-coded to break at the end of the most recent joke (my next hurdle is to iterate through this list)
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:template match="/">
<xsl:apply-templates select="//item[position() < 2]"/>
</xsl:template>
<xsl:template match="item">
<content-item>
<h1><xsl:value-of select="title"/></h1>
<p><xsl:value-of select="substring-before(description, 'mower')" disable-output-escaping="yes"/></p>
<br/><br/>
<p>"The following is here for testing purposes and will be removed"<br/><br/><xsl:value-of select="substring-after(description, 'lawn')" disable-output-escaping="yes"/></p>
<br/><br/>
</content-item>
</xsl:template>
</xsl:stylesheet>
I am rendering my output via a SharePoint 2013 RSS feed web part
In trying to view the proper XML I discovered the solution. I viewed the page source for my source URL, and in that I saw that the final characters are displayed as follows:
<title>Hunting with a wife #Joke #Humor</title><description>A hunter visited another hunter and was given a tour of his home. In the den was a stuffed lion.<br /><br />The visiting hunter asked, "when did you bag him?"<br /><br />The host said, "that was three years ago, when I went hunting with my wife."<br /><br />"What's he stuffed with," asked the visiting hunter. "My wife."<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/DailyJokes-ACleanJokeEveryday?a=RT1LsKVBV3Y:0LcrJjJq2X4:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/DailyJokes-ACleanJokeEveryday?d=yIl2AUoC8zA" border="0"></img></a> <a href....
The point being, the a href doesnt have a < it uses HTML markup <.
substring-before(description, '<a href') works.

Unable to get the value of 'xml:lang' attribute

<xoe:documents xmlns:xoe="http://xxxxxx" count="1">
<xocs:doc xmlns:xocs="xxxxxx" xmlns:xsi="yyyyyyy" xsi:schemaLocation="zzzzzz">
<xocs:meta>...</xocs:meta>
<xocs:serial-item>
<!-- this line -->
<article xmlns:sa="www.google.hgy" xmlns="http://www.xyzq1.org/xml/ja/dtd" version="5.4" xml:lang="pl" docsubtype="rev">
<article-info>
</article-info>
</article>
</xocs:serial-item>
</xocs:doc>
</xoe:documents>
I am unable to get the value of 'xml:lang' attribute. Even thought I tried with the below xpath
<xsl:variable name="rootPath" select="/xoe:documents/xocs:doc/xocs:serial-item"/>
<xsl:variable name="lang" select="$rootPath/ja:article[#xml:lang]"/>
or
<xsl:variable name="lang" select="$rootPath/ja:article/#xml:lang"/>
here ja is already defined in my xslt code
xmlns:ja="http://www.xyzq1.org/xml/ja/dtd"
Can some one please help?
First, you need to declare these:
xmlns:xoe="http://xxxxxx"
xmlns:xocs="xxxxxx"
xmlns:ya="www.yahoo.mkt"
Then you can get the value of the xml:lang attribute using:
<xsl:value-of select="/xoe:documents/xocs:doc/xocs:serial-item/ya:article/#xml:lang"/>
Note that the URIs in your stylesheet namespace declarations must be the same URIs that appear in your source XML. The prefixes can be anything you like.

How to select a property of a macro parameter in XSLT?

This is a very basic XSL question and I am just getting started with the topic in the context of Umbraco:
I've defined a macro with a XSLT file. The macro has a parameter of type 'ContentPicker'. What I want to do with the macro, is to render the picked content in a certain way. The relevant bit of my XSLT file is this:
<xsl:param name="source" select="/macro/BlogPostSource"/>
<xsl:template match="/">
<div>
<xsl:value-of select="$source/blogPostIntroduction"/>
</div>
I define a parameter, which is set to the parameter of the macro (this works). Now I simply want to render the property blogPostIntroduction which is a generic property on the picked content. This doesn't work. If I use
<xsl:value-of select="$source"/>
the ID of the content is rendered.
Question A: How do I select fields of the selected content?
Question B: Is my idea correct in general or am I missing a better way to do what I need, rather than using macros and XSLT?

XSLT parameter is always empty <xsl:param name="mediaFolderId" select="/macro/mediaFolderId" />

I created an xslt called GraphicsRowSlider with the following parameters
<xsl:param name="mediaFolderId" select="/macro/mediaFolderId" />
<xsl:param name="title" select="/macro/title" />
And added the parameters title and mediaFolderId to the related macro.
I then created new Macro Container data type and selected the macro GraphicsRowSlider as allowed macro. I then added a new field of the new data type into a document type and then imported that field into a template.
Finally, from the content, I inserted the macro and added a title and selected media folder... However, I could see that the macro calls the correct xslt with the correct title and mediaFolderId but the parameters are always empty!
Any thought?! Note, I always get this
<?UMBRACO_MACRO macroalias="GraphicsRowSlider" title="Add Title here" mediaFolderId="1159" />
The syntax you are using suggests that you are using an old umbraco version, which one are you using?
The definition how to work with macro parameters can be found on the umbraco wiki: http://our.umbraco.org/wiki/reference/templates/umbracomacro-element/macro-parameters
hth
Your input is an attribute (at least your xml example suggests this) so your xpath should look like this:
<xsl:param name="mediaFolderId" select="/macro/#mediaFolderId" />
<xsl:param name="title" select="/macro/#title" />