I have the following XSLT script which works great... however I need to access TAGS and not just a standard property value.
<!-- Build an XML variable with all the filters available --> <xsl:variablename="filterProxy"> <filterid="6624"property="facultyBuilding"value="HPA I"/> <filterid="3385"property="facultyDepartment"value="Social Work"/> <!-- HOW DO I CALL VALUES FROM TAGS???? --> </xsl:variable>
<!-- Grab the filter that applies to the current page --> <xsl:variablename="facultyFilter"select="msxml:node-set($filterProxy)/filter[@id = $currentPage/@id]"/>
<!-- Grab the root node to do lookups under --> <xsl:variablename="rootNode"select="umbraco.library:GetXmlNodeById(6394)"/>
<!-- Filter the FacultyProfile nodes using the filter (or return all of them if no filter matched) --> <xsl:for-each select="$rootNode/FacultyProfile[*[name() = $facultyFilter/@property] = $facultyFilter/@value] | $rootNode/FacultyProfile[not($facultyFilter)]"> <p> <xsl:value-ofselect="@nodeName"/> <!-- ETC. --> </p> </xsl:for-each>
I was hoping that it would be simple and follow the same format:
Where "facultyAffiliations" is the alias of the TAG dataType and "Tech Committe" would be one of the TAGS selected. But it doesn't quite work out that easy.
I guess you're using the built-in "Tags" DataType, which saves the tags as a comma-separated string (e.g.: "Code,XSLT,JavaScript") - and this means a little more work... but I think we'll need just a little more info on how you're expecting this to work – i.e., can you describe the scenario you're trying to match?
Will you only ever be matching against a single tag at a time or could there maybe be several?
As for the senerio, I use the Tags DataType for a section called "Affiliations". Which allows the faculty members to quickly list any Committees or Oraganizations that they might be connected to. So for example, I might be on the Diversity Committee, Technology Committee and in the Social Media Managers Group. So I would add those tags to my profile. Now as the web developer I might want to create a page for the Technology Committee and pull out and list all the faculty members that are on that Committee. Which is where I had hoped....
would have worked.. however tags are a little tricker than just that.
So far, I can only see the need to create a list based on one tag at a time, however I guess it's always nice to have the option should I need to call a combination if that was something that could be done.
Okay - Niels's code has a lot of what you need, actually - but this is the point where I'd normally get someone to write an extension for me - the logic needed to do all the things you want is much better encapsulated in a C# extension, so your "view" code can do what it's supposed to. Just think about it - what you really want to do is something like this:
<!-- Build an XML variable with all the filters available -->
<xsl:variable name="filterProxy">
<filter id="6624" property="facultyBuilding" value="HPA I" />
<filter id="3385" property="facultyDepartment" value="Social Work" />
<filter id="4490" property="facultyAffiliations" tags="Tech Committee" />
<filter id="4492" property="facultyAffiliations" tags="Tech Committee,Other Tag" />
</xsl:variable>
<!-- Grab the filter that applies to the current page -->
<xsl:variable name="facultyFilter" select="msxml:node-set($filterProxy)/filter[@id = $currentPage/@id]" />
<!-- Grab the root node to do lookups under -->
<xsl:variable name="rootNode" select="umbraco.library:GetXmlNodeById(6394)" />
<xsl:template match="/">
<!-- Process the <filter> with the appropriate template -->
<xsl:apply-templates select="$facultyFilter" />
</xsl:template>
<!-- Template for a VALUE filter -->
<xsl:template match="filter[@value]">
<xsl:variable name="nodes" select="ffc:FilterNodesByValue($rootNode/FacultyProfile, @value)" />
<xsl:apply-templates select="$nodes | $rootNode/FacultyProfile[not($facultyFilter)]" />
</xsl:template>
<!-- Template for a TAGS filter -->
<xsl:template match="filter[@tags]">
<xsl:variable name="nodes" select="ffc:FilterNodesByTags($rootNode/FacultyProfile, @tags)" />
<xsl:apply-templates select="$nodes | $rootNode/FacultyProfile[not($facultyFilter)]" />
</xsl:template>
<!-- Actual output template -->
<xsl:template match="FacultyProfile">
<p>
<xsl:value-of select="@nodeName" />
</p>
</xsl:template>
Where the ffc: prefix of course is bound to your extension - see this guide for how to build it yourself...
You *can* do the filtering in XSLT but the code needed to do bulletproof tag-matching in CSV strings will vastly degrade the readability of the actual view code. Hope I'm not too discouraging by answering this way :-)
Hmmm, well it's certainly helpful to know the most optimized way to do it.. I sure do seem to play in the deep in a lot. ;) thanks for your help thus far.
Build an XML variable with filters based on TAGS
I have the following XSLT script which works great... however I need to access TAGS and not just a standard property value.
I was hoping that it would be simple and follow the same format:
Where "facultyAffiliations" is the alias of the TAG dataType and "Tech Committe" would be one of the TAGS selected. But it doesn't quite work out that easy.
Any suggestions how I can make this work?
Thanks in advance
Hi FarmFreshCode,
I guess you're using the built-in "Tags" DataType, which saves the tags as a comma-separated string (e.g.: "Code,XSLT,JavaScript") - and this means a little more work... but I think we'll need just a little more info on how you're expecting this to work – i.e., can you describe the scenario you're trying to match?
Will you only ever be matching against a single tag at a time or could there maybe be several?
/Chriztian
Hi FarmFreshCode,
I just build a version, not so many days ago for built-in tags and masonry, with filters in Umbraco 6.1 and Bootstrap 2.3.x:
Hope this can help you out for the matter of filters as well :)
Remember to register the following to your /config/xsltExtensions.config:
Kind regards,
Niels
Hello Chriztian,
Yes, I am using the built in Tags DataType.
As for the senerio, I use the Tags DataType for a section called "Affiliations". Which allows the faculty members to quickly list any Committees or Oraganizations that they might be connected to. So for example, I might be on the Diversity Committee, Technology Committee and in the Social Media Managers Group. So I would add those tags to my profile. Now as the web developer I might want to create a page for the Technology Committee and pull out and list all the faculty members that are on that Committee. Which is where I had hoped....
would have worked.. however tags are a little tricker than just that.
So far, I can only see the need to create a list based on one tag at a time, however I guess it's always nice to have the option should I need to call a combination if that was something that could be done.
Hi FarmFreshCode,
Okay - Niels's code has a lot of what you need, actually - but this is the point where I'd normally get someone to write an extension for me - the logic needed to do all the things you want is much better encapsulated in a C# extension, so your "view" code can do what it's supposed to. Just think about it - what you really want to do is something like this:
Where the ffc: prefix of course is bound to your extension - see this guide for how to build it yourself...
You *can* do the filtering in XSLT but the code needed to do bulletproof tag-matching in CSV strings will vastly degrade the readability of the actual view code. Hope I'm not too discouraging by answering this way :-)
/Chriztian
Hmmm, well it's certainly helpful to know the most optimized way to do it.. I sure do seem to play in the deep in a lot. ;) thanks for your help thus far.
is working on a reply...