Problem with pulling data from document type property
Hi, I am upgrading our site from 4.0.4.2 to 6.1.6 and i'm having issues with one of my XSLT pages. I know the schema has changed so I ran it through a converter I found on a website.
The web page is meant to display news articles by year and I have a property set up to put the date in. I then have a drop down box which I select 2014 from and it has to compare 2014 to the date property to find all those with 2014 in. This isn't working at the moment and wondered if somebody could see what i'm doing wrong. articleDate below is the property I have set up as a date field.
<xsl:when test="$source/node[@nodeTypeAlias=$documentTypeAlias and contains(articleDate, umbraco.library:RequestQueryString('sidebar-select'))]">
<xsl:apply-templates select="$source/node[@nodeTypeAlias=$documentTypeAlias and contains(articleDate, umbraco.library:RequestQueryString('sidebar-select'))]">
$documentTypeAlias has the following code behind it where news item is the name of the document type being used to put all the articles in:
The main culprit in your code is the use of node - that's the thing that was changed in the schema. Here's a breakdown of how to do this - it's always a good idea to use a couple of intermediate variables for clarity (and you don't have to repeat a long XPath):
<!-- Grab year from QueryString -->
<xsl:variable name="year" select="umbraco.library:RequestQueryString('sidebar-select')" />
<!-- Grab the nodes for that year -->
<xsl:variable name="nodes" select="$source/*[@isDoc][name() = $documentTypeAlias][starts-with(articleDate, $year)]" />
...
<xsl:when test="$nodes">
<xsl:apply-templates select="$nodes" />
</xsl:when>
Note: I assume you're going for something else in the <xsl:otherwise>, so I didn't change that, but if you were to just do the apply-templates, it would only execute if the $nodes variable had any actual nodes in it - thus, no real reason to test for that...
Problem with pulling data from document type property
Hi, I am upgrading our site from 4.0.4.2 to 6.1.6 and i'm having issues with one of my XSLT pages. I know the schema has changed so I ran it through a converter I found on a website.
The web page is meant to display news articles by year and I have a property set up to put the date in. I then have a drop down box which I select 2014 from and it has to compare 2014 to the date property to find all those with 2014 in. This isn't working at the moment and wondered if somebody could see what i'm doing wrong. articleDate below is the property I have set up as a date field.
$documentTypeAlias has the following code behind it where news item is the name of the document type being used to put all the articles in:
I can show the whole code if it makes it easier but I assume the problem is in the first bit of code.
Many thanks.
Hi Simon,
The main culprit in your code is the use of node - that's the thing that was changed in the schema. Here's a breakdown of how to do this - it's always a good idea to use a couple of intermediate variables for clarity (and you don't have to repeat a long XPath):
Note: I assume you're going for something else in the
<xsl:otherwise>
, so I didn't change that, but if you were to just do the apply-templates, it would only execute if the $nodes variable had any actual nodes in it - thus, no real reason to test for that.../Chriztian
Hi Chriztian, thank you so much for your help, that's fixed it.
Many thanks for your help.
Simon
is working on a reply...