Generating content based on tags in Umbraco

618 views Asked by At

Umbraco, or rather xslt, seems to give me errors when I try to generate a list of content nodes based on a specific tag.

Consider the following code in a Macro:

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:msxml="urn:schemas-microsoft-com:xslt"
xmlns:tagsLib="urn:tagsLib"
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" 
exclude-result-prefixes="msxml tagsLib umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">
<xsl:output method="xml" omit-xml-declaration="yes"/>

<xsl:param name="currentPage"/>

<xsl:variable name="location"  select="$currentPage/othertag" />

<xsl:template match="/">
<div class="more-news">
  <xsl:value-of select="$currentPage/location"/>
  <h4>More news from <span class="capitalize"><xsl:value-of select="$location"/></span></h4>
  <ul>
    <xsl:for-each select="tagsLib:getEverythingWithTags('somalia')/root/node">
      <li><a href="#"><xsl:value-of select="@nodeName"/></a></li>
      <xsl:value-of select="@nodeUrl"/>
    </xsl:for-each>
  </ul>
</div>
</xsl:template>

</xsl:stylesheet>

What I'm trying to do here is finding all the content with a tag (location) defined on the current page. The above setup will work fine for finding all pages with location-tag 'somalia'.

The line:

<xsl:for-each select="tagsLib:getEverythingWithTags('somalia')/root/node">

should (I think) be:

<xsl:for-each select="tagsLib:getEverythingWithTags($location)/root/node">

But saving the code like that gives me the following error:

umbraco.DataLayer.SqlHelperException: Umbraco Exception (DataLayer): SQL helper exception in ExecuteReader ---> System.Data.SqlClient.SqlException: Incorrect syntax near ')'. 
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) 
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning() 
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) 
at System.Data.SqlClient.SqlDataReader.ConsumeMetaData() 
at System.Data.SqlClient.SqlDataReader.get_MetaData() 
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) 
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) 
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) 
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) 
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) 
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior) 
at Microsoft.ApplicationBlocks.Data.SqlHelper.ExecuteReader(String connectionString, CommandType commandType, String commandText, SqlParameter[] commandParameters) 
at umbraco.DataLayer.SqlHelpers.SqlServer.SqlServerHelper.ExecuteReader(String commandText, SqlParameter[] parameters) 
at umbraco.DataLayer.SqlHelper`1.ExecuteReader(String commandText, IParameter[] parameters) 
--- End of inner exception stack trace --- 
at umbraco.DataLayer.SqlHelper`1.ExecuteReader(String commandText, IParameter[] parameters) 
at umbraco.cms.businesslogic.Tags.Tag.GetNodesWithTags(String tags) 
at umbraco.editorControls.tags.library.getEverythingWithTags(String tags)

Any help and thoughts appreciated.

1

There are 1 answers

0
Mohammed Boutebel On

Hav you checked the content of "$currentPage/othertag" with this line code :

<xsl:value-of select="$currentPage/othertag" />

After that, you should put this code line in your xslt instead of your foreach loop :

<xsl:value-of select="tagsLib:getEverythingWithTags($location)" />

and check the content of the tags.