根据Umbraco中的标签生成内容

时间:2012-05-02 00:29:55

标签: xslt umbraco umbraco-tags

当我尝试根据特定标签生成内容节点列表时,Umbraco,或者更确切地说是xslt,似乎给了我错误。

考虑宏中的以下代码:

<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>

我在这里要做的是找到当前页面上定义的标签(位置)的所有内容。上面的设置可以很好地找到所有带有location-tag'somalia'的页面。

该行:

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

(我认为)应该是:

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

但保存这样的代码会给我带来以下错误:

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)

感谢任何帮助和想法。

1 个答案:

答案 0 :(得分:0)

你用这个行代码检查了“$ currentPage / othertag”的内容:

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

之后, 你应该把这段代码放在你的xslt而不是你的foreach循环中:

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

并检查标签的内容。