I have about 1,000 products on a website and I want to have a page list them - BUT - only if they meet a certain doctype alias. So for instance a page might show all Ford vehicles. So the "Manufacturer" doctype property within my 1,000 items needs to say "Ford" in order to show in my XSLT.
I would like to know how to do this also from the SAME level as the page that I would add the Macro onto. So they are not all child pages, they are on the same level.
You're right - it's not at all difficult with XSLT. Take a look at the following for a simple approach:
<xsl:param name="currentPage" />
<xsl:variable name="siteRoot" select="$currentPage/ancestor-or-self::*[@level = 1]" />
<xsl:template match="/">
<!-- Any Ford at or below $currentPage (substitute $siteRoot for $currentPage to grab all Fords in entire site) -->
<xsl:apply-templates select="$currentPage/descendant-or-self::*[@isDoc][manufacturer = 'Ford']" />
</xsl:template>
<!-- Template for any Document Type -->
<xsl:template match="*[@isDoc]">
<!-- do stuff -->
</xsl:template>
Thanks so much for helping. Unfortunately I don't have it working yet. It needs to be the complete site, as you thought about...I am putting all of the "Products" in one folder in Umbraco, so that they are easier to handle.
So I changed it to me siteRoot and put in my alias (Make). Do you know what I am doing wrong? My code is below. Please remember I am on 4.0.2.1.
<!-- Any Ford at or below $currentPage (substitute $siteRoot for $currentPage to grab all Fords in entire site) --> <xsl:apply-templates select="$siteRoot/descendant-or-self::*[@isDoc][Make='Ford']"/> </xsl:template>
<!-- Template for any Document Type --> <xsl:template match="*[@isDoc]">
If it's not too much trouble, I have one follow-up question:
How would you change this if you wanted it to be Make = Same as the current page's Make. In other words, I would make a category page with the same property and put "Ford" in it. That way, I can do one Macro and have it work for all categories.
Then, what if I also wanted to make it have to be "Mustang" for the Model.
So in essense:
Show all pages in the entire site that match model and make properties of the category page.
You do this by adding or augmenting the "predicate(s)" (an expression in square brackets) - so to match the currentPage's Make, instead of supplying a value, you select that ono on the other side of the equals sign:
Need to display nodes of a given property alias
I have about 1,000 products on a website and I want to have a page list them - BUT - only if they meet a certain doctype alias. So for instance a page might show all Ford vehicles. So the "Manufacturer" doctype property within my 1,000 items needs to say "Ford" in order to show in my XSLT.
I would like to know how to do this also from the SAME level as the page that I would add the Macro onto. So they are not all child pages, they are on the same level.
Thanks in advance for any help you can offer!
Does anyone have any tips for this? I'm pretty sure it must be something that's not too difficult to do in XSLT. Thanks in advance for your time!
Hi singer777,
You're right - it's not at all difficult with XSLT. Take a look at the following for a simple approach:
/Chriztian
Chriztian,
Thanks so much for helping. Unfortunately I don't have it working yet. It needs to be the complete site, as you thought about...I am putting all of the "Products" in one folder in Umbraco, so that they are easier to handle.
So I changed it to me siteRoot and put in my alias (Make). Do you know what I am doing wrong? My code is below. Please remember I am on 4.0.2.1.
Thanks again!
<?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" xmlns:tagsLib="urn:tagsLib" xmlns:BlogLibrary="urn:BlogLibrary"
exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets tagsLib BlogLibrary ">
<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:param name="currentPage"/>
<xsl:variable name="siteRoot" select="$currentPage/ancestor-or-self::*[@level = 1]"/>
<xsl:template match="/">
<!-- start writing XSLT -->
<!-- Any Ford at or below $currentPage (substitute $siteRoot for $currentPage to grab all Fords in entire site) -->
<xsl:apply-templates select="$siteRoot/descendant-or-self::*[@isDoc][Make='Ford']"/>
</xsl:template>
<!-- Template for any Document Type -->
<xsl:template match="*[@isDoc]">
<xsl:value-of select="data [@alias = 'Make']"/>
<ul><li><h3><a href="{umbraco.library:NiceUrl(@id)}">
<xsl:value-of select="@nodeName"/></a></h3></li></ul>
test
</xsl:template>
</xsl:stylesheet>
Hi again,
Ah yes, of course - it's for the "legacy XML Schema" - you'll need to change a couple of things:
First change the way you grab $siteRoot (small change, but in a large site it will make a difference to take only <node> elements instead of 'any'):
then, the apply-templates instruction:
- and then the template itself:
- that's it - should be good to go!
/Chriztian
Thanks so much.
If it's not too much trouble, I have one follow-up question:
How would you change this if you wanted it to be Make = Same as the current page's Make. In other words, I would make a category page with the same property and put "Ford" in it. That way, I can do one Macro and have it work for all categories.
Then, what if I also wanted to make it have to be "Mustang" for the Model.
So in essense:
Show all pages in the entire site that match model and make properties of the category page.
Thank you!
Hi,
You do this by adding or augmenting the "predicate(s)" (an expression in square brackets) - so to match the currentPage's Make, instead of supplying a value, you select that ono on the other side of the equals sign:
To also match the Model, you add another predicate, so the complete selection goes like this:
/Chriztian
Oh - and it goes without saying that working with the new Schema would make this much more readable, i.e.:
- Just an appetizer, so you know what a newer version of Umbraco wil do for you :-)
/Chriztian
Thanks again, Chriztian. I am trying it all now!
Chriztian,
This worked wonderfully. Thank you. I ended up matching it to a NODE ID so that the current page doesn't have to have the same properties.
Chriztian,
This worked wonderfully. Thank you. I ended up matching it to a NODE ID so that the current page doesn't have to have the same properties.
is working on a reply...